I'll give you mine, you'll have to convert it though.
Automatic backups however often you want which can run on its own thread, perfecto.
Code:
package org.pwnxile.core;
import java.io.File;
import java.io.IOException;
import org.pwnxile.core.task.Task;
import org.pwnxile.util.CopyDirectory;
import org.pwnxile.util.DateAndTime;
public class Backup implements Runnable {
final int ONE_DAY_TICK = 144000;
final int CHECKS_PER_DAY = 2;
final String FROM = "./data/accounts", BACKUP = "./data/backup";
public void run() {
Engine.task.submit(new Task(ONE_DAY_TICK / CHECKS_PER_DAY) {
protected void execute() {
initialize();
}
});
}
private void initialize() {
final File file = new File(FROM);
final File to = new File(BACKUP + "/" + DateAndTime.getTodaysDate());
System.out.println("Backing up latest accounts to " + BACKUP + "/"
+ DateAndTime.getTodaysDate());
try {
CopyDirectory.copyDirectory(file, to);
} catch (IOException e) {
System.out.println("Failed to complete backup of accounts");
return;
}
}
}
Code:
package org.pwnxile.util;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
public class CopyDirectory {
public static void copyDirectory(File srcPath, File dstPath)
throws IOException {
if (dstPath.exists()) {
System.out.println("Todays accounts have already been backed up");
return;
}
if (srcPath.isDirectory()) {
dstPath.mkdirs();
String files[] = srcPath.list();
for (int i = 0; i < files.length; i++) {
copyDirectory(new File(srcPath, files[i]), new File(dstPath,
files[i]));
}
} else {
if (!srcPath.exists()) {
System.out.println("File or directory does not exist.");
System.exit(0);
} else {
InputStream in = new FileInputStream(srcPath);
OutputStream out = new FileOutputStream(dstPath);
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
}
}
}
}
Code:
package org.pwnxile.util;
import java.util.Calendar;
import java.util.GregorianCalendar;
public class DateAndTime {
public static String getTodaysDate() {
Calendar date = new GregorianCalendar();
return date.get(Calendar.DAY_OF_MONTH) + "."
+ (date.get(Calendar.MONTH) + 1) + "."
+ date.get(Calendar.YEAR);
}
static final String[] MONTHS = { "January", "February", "March", "April",
"May", "June", "July", "August", "September", "October",
"November", "December" };
public String getMonth(){
return MONTHS[Calendar.MONTH];
}
public int getYear(){
return Calendar.YEAR;
}
public int getDay(){
return Calendar.DAY_OF_MONTH;
}
}