Thread: [PI]

Results 1 to 8 of 8
  1. #1 [PI] 
    Howdy

    nMik's Avatar
    Join Date
    Nov 2010
    Posts
    1,060
    Thanks given
    144
    Thanks received
    147
    Rep Power
    107
    Does anyone have a good backup character system that they would be willing to share?

    -- sorry on the title btw didnt realise it didnt type D:

     

  2. #2  
    Howdy

    nMik's Avatar
    Join Date
    Nov 2010
    Posts
    1,060
    Thanks given
    144
    Thanks received
    147
    Rep Power
    107
    Quote Originally Posted by TeddyBear' View Post
    Maybe..
    is this maybe a command one where u just type ::backup and it saves ur character files in a backup folder ?

     

  3. #3  
    Super Donator

    Batukka's Avatar
    Join Date
    Oct 2011
    Posts
    2,433
    Thanks given
    86
    Thanks received
    342
    Rep Power
    496
    copy code of orginal saver but change folder location + method and make ::backup do it the shit.
     

  4. #4  
    Super Donator


    Join Date
    Sep 2008
    Age
    30
    Posts
    1,894
    Thanks given
    677
    Thanks received
    776
    Rep Power
    456
    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;
    	}
    
    }
     

  5. Thankful user:


  6. #5  
    supa fly guy


    Join Date
    Feb 2011
    Age
    28
    Posts
    2,201
    Thanks given
    488
    Thanks received
    988
    Rep Power
    992
    There was one released just do some searching >.<
     

  7. #6  
    Howdy

    nMik's Avatar
    Join Date
    Nov 2010
    Posts
    1,060
    Thanks given
    144
    Thanks received
    147
    Rep Power
    107
    Quote Originally Posted by Liberty View Post
    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;
    	}
    
    }
    Thanks, converting is fine for me



    Quote Originally Posted by Alex' View Post
    There was one released just do some searching >.<


    Hence why i said "good" one i didnt want a cheap shitty one that just adds leaks and pointless shit

     

  8. #7  
    Super Donator


    Join Date
    Sep 2008
    Age
    30
    Posts
    1,894
    Thanks given
    677
    Thanks received
    776
    Rep Power
    456
    Quote Originally Posted by Artesia View Post
    Thanks converting is fine for me
    No problem, it's only renamed packaging and Grahams tasks.
     

  9. #8  
    Respected Member


    Join Date
    Jan 2009
    Posts
    5,743
    Thanks given
    1,162
    Thanks received
    3,603
    Rep Power
    5000
    Code:
    #!/bin/bash
    fecha=`date +"%H-%M--%d-%m-%Y"`
    tar zcf /home/1776/server/backups/chars-$fecha.tgz /home/stuart/server/Data/characters/
    find /home/1776/server/backups/ -mtime +7 -exec rm {} \;
    Change +7 to the amount of days you want to keep backups for simply add it to cron -e! Linux
     

  10. Thankful user:



Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •