You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

947 lines
38 KiB

package gui;
import java.io.*;
import java.util.*;
class Backup implements Runnable {
meph meph;
private static String loadcreate = null;
private static String editorrun = null;
private static int linecounter = 0;
private static String changechoice = null;
private static String therest = null;
private static String new1 = null;
private static String s = null;
private static String scan = null;
private static String backuplocation = null;
private static String find_excluded_directory = null;
private static String finalpart = null;
private static String newstring = null;
private static String cchoice1 = null;
private static String restorelocation = null;
private static String originalinput = null;
private static String EXCLUDE_STATEMENT = "--exclude=";
public static String homebackupname = null;
public static String homebackuplocation = null;
public static String[] listconfigmenu = new String[100];
// public String Name;
//Boolean statements for the Thread. Creating a thread prevents the GUI from locking up.
public static String Finalpart;
public static boolean systembackup = false;
public static boolean hbackup = false;
public static boolean network = false;
public static boolean foldersync = false;
static String message;
public static void setFinalpart(String data) {
Finalpart = data;
}
public static void setMessage(String data) {
message = data;
}
public static String getMessage() {
return message;
}
public static boolean interupt = true;
public static String getFinalpart() {
return Finalpart;
}
public void run() {
if (foldersync) {
MephUtil.messageparserln("");
MephUtil.messageparserln("Syncing.......\n ");
MephUtil.shell(getFinalpart());
MephUtil.messageparserln("");
MephUtil.messageparserln("Syncing Complete!");
MephUtil.messageparserln("");
foldersync = false;
}
if (network) {
MephUtil.messageparserln("\n\nSyncing.......\n ");
MephUtil.shell(getFinalpart());
MephUtil.messageparser("\n\nSyncing Complete!");
network = false;
}
if (systembackup) {
Menu.halfmenu();
MephUtil.messageparser("\n" + "Running Backup configuration: " + Settings.Name);
MephUtil.shell(getFinalpart());
Settings.setSizecheckerstatus(2);
if (Settings.getSelinux() == 1) {
plugins.enableselinux();
}
if (Settings.modify != 0) {
Backup.restorefstab();
}
Settings.setCheckermessage("\nStatus of operation......\n\nFile Size = ");
MephUtil.filecheckerDie(Settings.Backuplocation + Settings.Name + ".tar");
MephUtil.messageparserln("\nBackup Complete!");
tarsize.tar();
systembackup = false;
}
if (hbackup) {
Menu.halfmenu();
MephUtil.messageparser("\n" + "Running Backup configuration.....");
MephUtil.shell(getFinalpart());
Settings.setSizecheckerstatus(2);
MephUtil.filecheckerDie(Backup.homebackuplocation + Backup.homebackupname + ".tar");
MephUtil.messageparser("\n\n" + "Backup operation complete!");
tarsize.setTar(Backup.homebackuplocation + Backup.homebackupname + ".tar");
tarsize.tar();
hbackup = false;
}
}
public static void texteditor(String configfile, String temp) {
try {
FileReader editorreader = new FileReader(configfile);
BufferedReader buffereditor = new BufferedReader(editorreader);
FileWriter editorwriter = new FileWriter(temp);
BufferedWriter buffereditorWriter = new BufferedWriter(editorwriter);
String stop = "run";
String editorr = null;
while ((editorr = buffereditor.readLine()) != null) {
if (stop.contains("run")) {
MephUtil.userinput("Welcome to the Mephiso Configuration Editor.\n\nThe configuration file *MUST* be in the same format to function correctly.\nPress enter to view the next line. Press e followed by enter to change the current line.\n\nType stop followed by enter to finish editing and save the changes.\n\n[Editing Configuration File]\n\nCurrent Line = " + editorr + "\n\nPress ok for next line. \n\n");
if (Settings.getInput() == null) {
buffereditorWriter.write(editorr + "\n");
} else {
if (Settings.getInput().equals("e")) {
MephUtil.userinput("New value: ");
String newedit = Settings.getInput();
editorr = newedit;
}
if (Settings.getInput().contains("stop")) {
stop = "stop";
}
buffereditorWriter.write(editorr + "\n");
}
}
}
buffereditorWriter.close();
} catch (IOException agfdyhtryt) {
}
try {
FileReader in = new FileReader(temp);
FileWriter out = new FileWriter(configfile);
int c;
while ((c = in.read()) != -1) {
out.write(c);
}
in.close();
out.close();
} catch (IOException tr) {
}
filecheckerDie(configfile);
MephUtil.messageparser("\n\nConfiguration Saved.....");
}
public static void choosebackup() {
if (!Settings.getRoot()) {
MephUtil.messageparser("\n\nError: You must be root for this action.");
} else {
//Scanner input = new Scanner(System.in);
int choi = 0;
MephUtil.userinput("Mephisto Backup Filesystem tools."
+ "\n\nWould you like to:\n\n"
+ "(1) Backup filesystem. \n\n"
+ "(2) Edit the configuration file \n\n"
+ "(3) Create new backup configuration. \n\n"
+ "(4) Delete configuration file. \n\n"
+ "Your choice: ");
if (Settings.getNumericalResponse() == 1) {
readconfigfile();
} else if (Settings.getNumericalResponse() == 2) {
editor();
} else if (Settings.getNumericalResponse() == 3) {
createbackup();
} else if (Settings.getNumericalResponse() == 4) {
Config.deleteconfig();
}
}
}
public static void readconfigfile() {
MephUtil.readconfigfile();
if (MephUtil.filechecker(Settings.getConfig_file())) {
MephUtil.listconfigs();
chooseconfig();
}
}
public static void chooseconfig() {
String Name;
int BackupNum = -1;
MephUtil.userinput("Saved configurations:\n\n" + Settings.listconfig + "\n\nWhich configuration would you like to load? "
+ "(enter the number, or type the name): \n\nName or number to load:");
Name = Settings.getInput();
if (Name.contains("!")) {
//return;
} else {
try {
BackupNum = Integer.parseInt(Name) - 1;
} catch (NumberFormatException n) {
/*
* It is not a number, see if it's a name!
*/
BackupNum = Settings.getConfigIndex(Name);
}
if (BackupNum == -1) {
MephUtil.messageparser("\n\nSorry, you don't appear to have"
+ " a config named " + Name);
//return;
}
// the new method below replaces the commented code. jan 16 2010 - nate
MephUtil.loadconfig(BackupNum);
previousbackup();
}
}
public static void previousbackup() {
//Added plugin to detect redhat and disable selinux as needed.
plugins.detectredhat();
backup();
}
public static void restorefstab() {
try {
String read = "";
FileReader frr = new FileReader("/tmp/fstab_original");
BufferedReader brr = new BufferedReader(frr);
FileWriter realfstab = new FileWriter("/etc/fstab");
BufferedWriter brealfstab = new BufferedWriter(realfstab);
while ((read = brr.readLine()) != null) {
brealfstab.write("\n" + read);
}
brr.close();
brealfstab.close();
} catch (IOException adas) {
}
}
public static void specificdirectory() {
String homedestination = "";
String homebackup = "";
String excludes = "";
MephUtil.userinput("Specific directory backup supports file extensions to exclude.\n\n\nThis feature is very useful to backup mounted server/filesystems accross a network.\n\nWould you like to exclude any filetypes? If so, type `yes` followed by enter. Type `no`\n\nfollowed by enter to not exclude a file. \n\nYour choice: ");
String anyexcludes = Settings.getInput();
if (anyexcludes.contains("yes")) {
excludes = getExcludes();
}
MephUtil.userinput("Directory to backup: (Make sure / is at the end) : ");
homedestination = Settings.getInput();
if (MephUtil.filechecker(homedestination)) {
MephUtil.userinput("Backup Name: ");
homebackupname = Settings.getInput();
MephUtil.userinput("Where to store the backup file: ");
homebackuplocation = Settings.getInput();
int lengthcheck = homebackuplocation.length();
String slashcheck = homebackuplocation.substring(lengthcheck,
lengthcheck);
if (slashcheck.contains(("/"))) {
} else {
homebackuplocation = homebackuplocation + "/";
}
if (MephUtil.filechecker(homebackuplocation)) {
homebackup = (Settings.path_tar + " czpf "
+ homebackuplocation
+ homebackupname
+ ".tar --exclude=/usr/src/* --exclude=/root/* --exclude=/usr/portage/* --exclude="
+ homebackupname + ".tar " + excludes + " " + homedestination);
MephUtil.messageparser(homebackup);
s = null;
MephUtil.messageparserln("");
//New way of thread handling for the GUI.
hbackup = true;
Thread tar = new Thread(new Backup());
Settings.setCheckermessage("\n\n " + "File Size= ");
Settings.setSizechecker(homebackuplocation + homebackupname
+ ".tar ");
Checker.startc();
setFinalpart(homebackup);
MephUtil.messageparserln("Backing up " + homedestination + " !");
tar.start();
} else {
Menu.halfmenu();
MephUtil.messageparser("Error: " + homebackuplocation + " not found!");
}
} else {
Menu.halfmenu();
MephUtil.messageparser("Error: " + homedestination + " not found!");
}
}
/**
* Returns a String generated by asking the user for the type of files that
* want to be excluded in the final tar. Uses StringBuffer for efficiency in
* appending excludes.
*
* @return a formatted exclude String for tar
*/
public static String getExcludes() {
StringBuffer excluded = new StringBuffer();
MephUtil.userinput("The following directories are automatically excluded:\n\n /home /sys /proc /dev /mnt /media\n\n\nFiletype/Directory to exclude i.e. *.txt to skip all .txt files (. to end): ");
String inputExclude = Settings.getInput();
// only exit when we see only a dot
while (!inputExclude.equals(".")) {
excluded.append(EXCLUDE_STATEMENT + inputExclude + " ");
MephUtil.userinput("Filetype to exclude i.e. *.txt to skip all .txt files (. to end): ");
inputExclude = Settings.getInput();
}
return excluded.toString();
}
public static void backup() {
Menu.halfmenu();
MephUtil.filecheckerDie(Settings.Backuplocation);
MephUtil.messageparser("\n\nRunning Backup configuration:\n "
+ Settings.Name + " ");
finalpart = (Settings.path_tar + " czpf "
+ Settings.Backuplocation
+ Settings.Name
+ ".tar "
+ "--exclude=/var/tmp/portage/* --exclude=/root/* --exclude=/usr/portage/* --exclude=*.deb --exclude=/tmp/* --exclude=*.rpm --exclude=/sys/* "
+ "--exclude=/proc/* --exclude=/dev/* --exclude=/mnt/* --exclude=/media/* --exclude=/home/* "
+ Settings.Excludes + " --exclude="
+ Settings.Name + ".tar" + " /");
Settings.setCheckermessage("\n Status of operation......\n\nFile Size = ");
Settings.setSizechecker(Settings.Backuplocation + Settings.Name
+ ".tar");
tarsize.setTar(Settings.Backuplocation + Settings.Name + ".tar");
//New way of thread handling for the GUI.
systembackup = true;
Thread tar = new Thread(new Backup());
Checker.startc();
setFinalpart(finalpart);
tar.start();
}
public static void createbackup() {
MephUtil.userinput("Please type a name for this backup:");
String name = Settings.getInput();
if (name == null) {
} else {
MephUtil.messageparserln("");
MephUtil.userinput("Where would you like to store this backup? "
+ "\n" + "\nExample: /tmp/ \n\n\n\nBackup Location: ");
backuplocation = Settings.getInput();
int lengthcheck = backuplocation.length();
String slashcheck = backuplocation.substring(lengthcheck,
lengthcheck);
if (slashcheck.contains(("/"))) {
} else {
backuplocation = backuplocation + "/";
}
File location = new File(backuplocation);
if (location.exists()) {
String exclude = getExcludes();
if (exclude.length() == 0) {
exclude = "none";
}
MephUtil.userinput("Woud you like to save this configuration? (y/n) ");
String save = Settings.getInput();
if (save.equals("n")) {
MephUtil.messageparserln("\n" + "\n"
+ "Thank you for using Mephisto Backup!");
} else if ((save.equals("y"))) {
try {
FileWriter out = new FileWriter(Settings.getConfig_file(), true);
BufferedWriter brout = new BufferedWriter(out);
String finall = ("\n" + "Name=" + name + "\n"
+ "Restorepath=" + restorelocation + "\n"
+ "Backuplocation=" + backuplocation + "\n"
+ "Excludes=" + exclude + "\n");
brout.write(finall);
brout.close();
} catch (IOException adsads) {
}
filecheckerDie(Settings.getConfig_file());
MephUtil.messageparser("\n\nConfiguration Saved.....");
} else {
Menu.pause("\nError: Invalid input.");
}
} else {
Menu.pause("\n\nError: Backuplocation not found!");
}
}
}
public static void editor() {
MephUtil.messageparserln("");
if (MephUtil.filechecker(Settings.getConfig_file())) {
texteditor(Settings.getConfig_file(), Settings.getConfig_file_tmp());
} else {
MephUtil.messageparser("Error: Config file does not exist!");
}
//return;
}
public static void networksync() {
String Name = "";
String seek2;
Settings.networkanswer[0] = "Name=";
Settings.networkanswer[1] = "Server=";
Settings.networkanswer[2] = "Source=";
Settings.networkanswer[3] = "Destination=";
String netreader = null;
int networkcounter1 = -1;
linecounter = 0;
MephUtil.userinput("Welcome to Mephisto Network Backup Sync!\n\nNetwork Backup Sync allows you to sync files or folders accross the network by using Rsync and ssh.\n\nIn order for this to work, you must already have a ssh key created. \n\nTo generate a key, please do the following: \n ssh-keygen \n ssh-copyid -i ~/.ssh/id.rsa.pub [email protected]\n\nWould you like to `l`oad` or `c`reate` or `e`dit a configuration? ");
loadcreate = Settings.getInput();
int proceede = 0;
if (loadcreate.contains("c")) {
proceede = 1;
networksynccreate();
}
if (loadcreate.contains("e")) {
proceede = 1;
networksyncedit();
}
if (loadcreate.contains("l")) {
proceede = 1;
if (MephUtil.filechecker(Config.getNetworkConfig())) {
networkcounter1 = -1;
MephUtil.messageparserln("");
StringBuffer networksaved = new StringBuffer();
try {
FileReader netfrr = new FileReader(Config.getNetworkConfig());
BufferedReader netbrr = new BufferedReader(netfrr);
while ((netreader = netbrr.readLine()) != null) {
if (netreader.contains("Name=")) {
networkcounter1++;
Settings.networkanswer[networkcounter1] = netreader;
String[] diablo = netreader.split("=");
Settings.networkanswer2[networkcounter1] = diablo[1];
networksaved.append(Settings.networkanswer2[networkcounter1]
+ "\n");
}
if (netreader.contains("Server=")) {
networkcounter1++;
Settings.networkanswer[networkcounter1] = netreader;
String[] diablo = netreader.split("=");
Settings.networkanswer2[networkcounter1] = diablo[1];
}
if (netreader.contains("Source=")) {
networkcounter1++;
Settings.networkanswer[networkcounter1] = netreader;
String[] diablo = netreader.split("=");
Settings.networkanswer2[networkcounter1] = diablo[1];
}
if (netreader.contains("Destination=")) {
networkcounter1++;
Settings.networkanswer[networkcounter1] = netreader;
String[] diablo = netreader.split("=");
Settings.networkanswer2[networkcounter1] = diablo[1];
networkcounter1 = networkcounter1 + 1;
}
if (netreader.contains("Username=")) {
Settings.networkanswer[networkcounter1] = netreader;
String[] diablo = netreader.split("=");
Settings.networkanswer2[networkcounter1] = diablo[1];
networkcounter1++;
}
linecounter = linecounter + 1;
}
MephUtil.userinput("Saved Configurations:\n\n" + networksaved.toString() + "\n\nWhich configuration would you like to load? : ");
Name = Settings.getInput();
proceede = 0;
netbrr.close();
netfrr.close();
} catch (IOException ads) {
}
try {
Settings.setProceede(1);
FileReader seekagain = new FileReader(Config.getNetworkConfig());
BufferedReader brrseek = new BufferedReader(seekagain);
networkcounter1 = 0;
linecounter = 0;
while ((seek2 = brrseek.readLine()) != null) {
if (seek2.contains(Name)) {
Settings.Name = Settings.networkanswer2[networkcounter1];
networkcounter1 = networkcounter1 + 1;
Settings.Server = Settings.networkanswer2[networkcounter1];
networkcounter1 = networkcounter1 + 1;
Settings.Source = Settings.networkanswer2[networkcounter1];
networkcounter1 = networkcounter1 + 1;
Settings.Destination = Settings.networkanswer2[networkcounter1];
networkcounter1 = networkcounter1 + 1;
Settings.Username = Settings.networkanswer2[networkcounter1];
linecounter = linecounter + 1;
Settings.setProceede(0);
break;
}
}
} catch (IOException fhjkn) {
}
if (Settings.getProceede() == 0) {
Menu.halfmenu();
MephUtil.userinput("Would you like to `b`ackup` or `r`estore` the configuration: "
+ Settings.Name);
editorrun = Settings.getInput();
if (editorrun.contains("b")) {
networksyncbackup();
}
if (editorrun.contains("r")) {
networksyncrestore();
}
} else {
Menu.halfmenu();
MephUtil.messageparser("\n\n Error:Invalid Configuration!");
}
} else {
Menu.halfmenu();
MephUtil.messageparser("\n\n Error: No configuration file found!");
}
}
}
public static void networksyncbackup() {
Thread syncnetwork = new Thread(new Backup());
setFinalpart(Settings.path_rsync + " -az -e ssh --delete " + Settings.Source + " "
+ Settings.Username + "@" + Settings.Server + ":" + Settings.Destination);
network = true;
syncnetwork.start();
}
public static void networksynccreate() {
String Name = "";
MephUtil.userinput("What would you like to name this backup? ");
Name = Settings.getInput();
MephUtil.userinput("What is the server hostname or IP address? ");
Settings.Server = Settings.getInput();
MephUtil.userinput("Directory to backup: ");
Settings.Source = Settings.getInput();
int lengthcheck = Settings.Source.length();
String slashcheck = Settings.Source.substring(lengthcheck,
lengthcheck);
if (slashcheck.contains(("/"))) {
} else {
Settings.Source = Settings.Source + "/";
}
if (MephUtil.filechecker(Settings.Source)) {
MephUtil.userinput("Destination directory on server: ");
String Destination = Settings.getInput();
int lengthcheck2 = Destination.length();
String slashcheck2 = Destination.substring(lengthcheck2,
lengthcheck2);
if (slashcheck2.contains(("/"))) {
} else {
Destination = Destination + "/";
}
MephUtil.userinput("Username on the server: ");
Settings.Username = Settings.getInput();
String netfinal = ("\n" + "Name=" + Name + "\n" + "Server="
+ Settings.Server + "\n" + "Source=" + Settings.Source
+ "\n" + "Destination=" + Destination + "\n" + "Username="
+ Settings.Username + "\n");
try {
FileWriter netfw = new FileWriter(Config.getNetworkConfig(), true);
BufferedWriter netbw = new BufferedWriter(netfw);
netbw.write(netfinal);
netbw.close();
netfw.close();
File checksave = new File(Config.getNetworkConfig());
if (checksave.exists()) {
MephUtil.messageparser("\n\nConfiguration Saved.....");
} else {
Menu.pause("\n\nError: Configuration file not saved. Please try again.");
}
} catch (IOException jkljl) {
}
} else {
Menu.halfmenu();
MephUtil.messageparser("\n\nError: " + Settings.Source + " not found!");
}
}
public static void networksyncedit() {
if (MephUtil.filechecker(Config.getNetworkConfig())) {
texteditor(Config.getNetworkConfig(), Settings.getConfig_file_tmp());
try {
FileReader in = new FileReader(Settings.getConfig_file_tmp());
FileWriter out = new FileWriter(Config.getNetworkConfig());
int c;
while ((c = in.read()) != -1) {
out.write(c);
}
in.close();
out.close();
} catch (IOException sadhjk) {
}
filecheckerDie(Settings.getConfig_file_tmp());
MephUtil.messageparser("\n\nConfiguration Saved.....");
} else {
Menu.halfmenu();
MephUtil.messageparser("\n\nError: Configuration file not found!");
}
}
public static void networksyncrestore() {
MephUtil.messageparserln("");
linecounter = 0;
String rrrsync = (Settings.path_rsync + " -az -e ssh " + Settings.Username + "@"
+ Settings.Server + ":" + Settings.Destination + " " + Settings.Source);
MephUtil.messageparserln("");
MephUtil.messageparserln("Restoring.......\n ");
MephUtil.shell(rrrsync);
MephUtil.messageparserln("");
MephUtil.messageparser("\n\nRestoring Complete!");
}
public static void foldersync() {
String seek2, Name = "";
Settings.networkanswer[0] = "Name=";
Settings.networkanswer[1] = "Source=";
Settings.networkanswer[2] = "Destination=";
String netreader = null;
int networkcounter1 = -1;
linecounter = 0;
MephUtil.userinput("Welcome to Mephisto Folder Sync!\n\nFolder Sync allows you to sync files and folders by using Rsync.\n\n\nWould you like to `l`oad` or `c`reate` or `e`dit a configuration?:");
loadcreate = Settings.getInput();
if (loadcreate.contains("c")) {
foldersynccreatebackup();
}
if (loadcreate.contains("e")) {
if (MephUtil.filechecker(Config.getSyncconfig())) {
foldersyncedit();
} else {
Menu.halfmenu();
MephUtil.messageparser("\n\nError: Configuration file not found!");
}
}
if (loadcreate.contains("l")) {
if (MephUtil.filechecker(Config.getSyncconfig())) {
networkcounter1 = -1;
StringBuffer foldersynclist = new StringBuffer();
try {
FileReader netfrr = new FileReader(Config.getSyncconfig());
BufferedReader netbrr = new BufferedReader(netfrr);
while ((netreader = netbrr.readLine()) != null) {
if (netreader.contains("Name=")) {
networkcounter1++;
Settings.networkanswer[networkcounter1] = netreader;
String[] diablo = netreader.split("=");
Settings.networkanswer2[networkcounter1] = diablo[1];
foldersynclist.append(Settings.networkanswer2[networkcounter1] + "\n");
}
if (netreader.contains("Source=")) {
networkcounter1++;
Settings.networkanswer[networkcounter1] = netreader;
String[] diablo = netreader.split("=");
Settings.networkanswer2[networkcounter1] = diablo[1];
}
if (netreader.contains("Destination=")) {
networkcounter1++;
Settings.networkanswer[networkcounter1] = netreader;
String[] diablo = netreader.split("=");
Settings.networkanswer2[networkcounter1] = diablo[1];
}
linecounter = linecounter + 1;
}
MephUtil.userinput("Saved Configurations:\n\n" + foldersynclist.toString() + "\n\nWhich configuration would you like to load? ");
Name = Settings.getInput();
netbrr.close();
netfrr.close();
} catch (IOException sadsads) {
}
try {
Settings.setProceede(1);
FileReader seekagain = new FileReader(Config.getSyncconfig());
BufferedReader brrseek = new BufferedReader(seekagain);
networkcounter1 = 0;
linecounter = 0;
while ((seek2 = brrseek.readLine()) != null) {
if (seek2.contains(Name)) {
Settings.Name = Settings.networkanswer2[networkcounter1];
networkcounter1 = networkcounter1 + 1;
Settings.Source = Settings.networkanswer2[networkcounter1];
networkcounter1 = networkcounter1 + 1;
Settings.Destination = Settings.networkanswer2[networkcounter1];
networkcounter1 = networkcounter1 + 1;
linecounter = linecounter + 1;
Settings.setProceede(0);
break;
}
}
brrseek.close();
} catch (IOException adsads) {
}
if (Settings.getProceede() == 1) {
gui.Menu.invalidselection();
foldersync();
}
if (Settings.getProceede() == 0) {
MephUtil.userinput("Would you like to `b`ackup` or `r`estore the configuration: "
+ Settings.Name + " : ");
editorrun = Settings.getInput();
if (editorrun.toLowerCase().equals("b")) {
foldersyncbackup();
} else if (editorrun.toLowerCase().equals("r")) {
foldersyncrestore();
} else {
gui.Menu.invalidselection();
}
}
} else {
MephUtil.messageparser("\n\nError: You did not create a configuration file yet.");
}
}
}
public static void foldersyncrestore() {
MephUtil.messageparserln("");
linecounter = 0;
MephUtil.filecheckerDie(Settings.Destination);
setFinalpart(Settings.path_rsync + " -az " + Settings.Destination + " " + Settings.Source);
foldersync = true;
Thread folderRestore = new Thread(new Backup());
folderRestore.start();
}
public static void foldersyncbackup() {
MephUtil.filecheckerDie(Settings.Destination);
setFinalpart(Settings.path_rsync + " -az " + Settings.Source + " " + Settings.Destination);
foldersync = true;
Thread folderBackup = new Thread(new Backup());
folderBackup.start();
}
public static void foldersynccreatebackup() {
MephUtil.userinput("What would you like to name this backup? ");
Settings.Name = Settings.getInput();
MephUtil.userinput("What is the destination folder? : ");
Settings.Destination = Settings.getInput();
if (MephUtil.filechecker(Settings.Destination)) {
int lengthcheck = Settings.Destination.length();
String slashcheck = Settings.Destination.substring(lengthcheck,
lengthcheck);
if (slashcheck.contains(("/"))) {
} else {
Settings.Destination = Settings.Destination + "/";
}
Menu.halfmenu();
MephUtil.userinput("Directory to backup? : ");
Settings.Source = Settings.getInput();
if (MephUtil.filechecker(Settings.Source)) {
int lengthcheck3 = Settings.Source.length();
String slashcheck3 = Settings.Source.substring(lengthcheck3,
lengthcheck3);
if (slashcheck3.contains(("/"))) {
} else {
Settings.Source = Settings.Source + "/";
}
File checksource = new File(Settings.Source);
if (checksource.exists()) {
String netfinal = ("\n" + "Name=" + Settings.Name + "\n"
+ "Source=" + Settings.Source + "\n"
+ "Destination=" + Settings.Destination + "\n");
try {
FileWriter netfw = new FileWriter(Config.getSyncconfig(), true);
BufferedWriter netbw = new BufferedWriter(netfw);
netbw.write(netfinal);
netbw.close();
netfw.close();
MephUtil.messageparserln("");
MephUtil.messageparser("\n\nConfiguration Saved!");
} catch (IOException sads) {
}
} else {
gui.Menu.invalidselection();
foldersync();
}
} else {
Menu.halfmenu();
MephUtil.messageparser("\n\nError: " + Settings.Source + " not found!");
}
} else {
Menu.halfmenu();
MephUtil.messageparser("\n\nError: " + Settings.Destination + " does not exist!");
}
}
public static void foldersyncedit() {
MephUtil.messageparserln("");
if (MephUtil.filechecker(Config.getSyncconfig())) {
texteditor(Config.getSyncconfig(), Settings.getConfig_file_tmp());
} else {
Menu.halfmenu();
MephUtil.messageparser("\n\nError: config file not found!");
}
}
public static void homebackup() {
String homedestination = "";
String homebackup = "";
String excludes = "";
Menu.halfmenu();
MephUtil.userinput("Home directory backup supports file extensions to exclude.\n\nWould you like to exclude any filetypes?\n\nIf so, type `yes` followed by enter.\n\nType `no` followed by enter to not exclude a file. \n\n\n Your choice: ");
String anyexcludes = Settings.getInput();
if (anyexcludes.contains("yes")) {
excludes = getExcludes();
}
Menu.clearscreen();
Menu.halfmenu();
MephUtil.userinput("Which home directory do you want to be backed up?\n\n(no need to type /home/)");
homedestination = Settings.getInput();
homedestination = "/home/" + homedestination;
MephUtil.filechecker(homedestination);
if (MephUtil.filechecker(homedestination)) {
MephUtil.userinput("Backup Name:");
homebackupname = Settings.getInput();
MephUtil.userinput("Where to store the backup file:");
homebackuplocation = Settings.getInput();
int lengthcheck = homebackuplocation.length();
String slashcheck = homebackuplocation.substring(
lengthcheck, lengthcheck);
if (slashcheck.contains(("/"))) {
} else {
homebackuplocation = homebackuplocation + "/";
}
homebackup = (Settings.path_tar + " czpf " + homebackuplocation
+ homebackupname + ".tar --exclude="
+ homebackupname + ".tar " + excludes
+ " " + homedestination);
MephUtil.messageparser(homebackup);
s = null;
if (MephUtil.filechecker(homebackuplocation)) {
hbackup = true;
Thread tar = new Thread(new Backup());
Settings.setCheckermessage("\n\n " + "File Size= ");
Settings.setSizechecker(homebackuplocation + homebackupname
+ ".tar ");
Checker.startc();
setFinalpart(homebackup);
MephUtil.messageparserln("Backing up " + homedestination + " !");
tar.start();
} else {
Menu.halfmenu();
MephUtil.messageparser("\n\nError: " + homebackuplocation + " no found!");
}
} else {
MephUtil.messageparserln("\n\nError: Home Directory not found!\n");
}
}
/*
* Wrapper functions from MephUtil to ease on typing
*/
public Boolean shell(String command) {
return MephUtil.shell(command);
}
public Boolean shell(String command, Boolean output) {
return MephUtil.shell(command, output);
}
public static void filecheckerDie(String what) {
MephUtil.filecheckerDie(what);
}
}