RuneScape 2 Development > Downloads

[Tool] Automated Backup Utility

Pages: (1/2) >>>

CSharp95:

Travis' Automated Backup Utility
Here's another quick tool I made, this time for server owners and developers.

What it does
It simply backs up the provided directory to a zip file, removing the need for manual or integrated backup methods.
While it's designed with backing up the player files in mind, you can really backup anything you'd like with it. Databases, Logs, whatever suits your purposes. So long as it's all saved in a local directory, it should be able to read it.

Why it's needed
Many servers that are smaller do not keep backups of their players, and if they do, it's typically done manually about once a day, meaning it's still possible to lose an entire day worth of work(or sometimes having to start completely over) just due to the host having to switch VPS providers. This has happened far too many times for me, whether it be an economy reset or switching hosts, it's been the reason a lot of people quit a server.
This ensure that there will always be an up-to-date backup available for the host to use, so long as this is used properly.

How to use it
It takes 2 arguments, so you should set it up to run through a .bat file.
1. The directory you wish to backup, I.E the folder with all of your player files in it
2. The rate of backups in minutes

Example: RSPSABU "c:/rsps/data/players" 20
Will backup the directory c:/rsps/data/players to a zip file every 20 minutes

If you're hosting on a VPS, it is highly recommended that you keep this program in a cloud storage folder such as google drive to ensure that you can get to the backups even if your VPS goes down or service stops!

Disk Space
Keep in mind how much space you have so you don't go too crazy with the amount of backups. If you have about 3-4mb of players, you'll only use up about 500mb of space per month, but with 20mb of players you'll use up almost 4gb of space in the same time span.
I personally recommend one backup every 4 hours, that gives you 6 backups a day, however it just depends on how much you have to work with.

Download
Requires the .NET framework 4.5.1 found here[/url]
Virus Scan: https://www.virustotal.com/en/file/658faa8e8ce79e2b8d45773627ff86f355800f6cc03d1a5c17c33b8acbd06f2b/analysis/1433589621/

Uppit: RSPSABU.zip - 3 KB

Source
The source is small enough to fit in a code block since it was a single class.
Written in C# using Visual Studio
(click to show/hide)Add two references: System.IO.Compression and System.IO.Compression.FileSystem

--- Code: ---using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.IO.Compression;
using System.Threading;

namespace RSPSABU
{
    class RSPSABU
    {
        static string _PlayerDir;
        static int _BackupTime;
        static string _CurTime;
        static void Main(string[] args)
        {
            try
            {
                _PlayerDir = args[0];
                _BackupTime = Convert.ToInt32(args[1]);
            }
            catch(Exception e)
            {
                Console.WriteLine("Invalid application arguments, see included text file for usage information");
                Console.Write("Press any key to exit");
                Console.ReadKey();
                Environment.Exit(1);
            }
            Console.Title = "Automated Backup Utility";
            Console.WriteLine("RuneScape Private Server Automated Backup Utility");
            Console.WriteLine("Written by CSharp95/Travis, contact at traviscondren95@gmail.com");
            Thread.Sleep(3000);
            Console.Clear();
            Console.WriteLine("Directory {0} will be archived every {1} minutes", _PlayerDir, _BackupTime);
            int _l = 0;
            int _n;
            Console.WriteLine("Starting backup loop");
            while (_l <= _BackupTime)
            {
                if (_l == _BackupTime)
                {
                    _CurTime = GetDate();
                    Console.WriteLine("Backing up " + _CurTime);
                    CompressFile(_PlayerDir);
                    _l = 0;
                }
                else
                {
                    _n = _BackupTime - _l;
                    Console.WriteLine("Next backup in " + _n + " minutes");
                    _l++;
                    SleepThread(1);
                }
            }
        }
        static string GetDate()
        {
            string _result = DateTime.Now.ToString("yyyy-MM-dd hh-mm");
            return _result;
        }
        static void CompressFile(string _file)
        {
            try
            {
                ZipFile.CreateFromDirectory(_PlayerDir, _CurTime + ".zip");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
        static void SleepThread(int _time)
        {
            _time = _time * 60000;
            Thread.Sleep(_time);
        }
    }
}


--- End code ---
Not the cleanest but there's not much to learn from here, so I decided against commenting it.

As always, please leave feedback, good or bad it's appreciated.

Cres:

maybe have an option where the backup overwrites previous backups but only for x times

this will prevent the backups taking up heaps of memory while still providing enough back-ups to switch back to

other than that, it's nice but such a thing really doesn't take a lot of work to make
hope people will make use of it

CSharp95:


--- Quote from: Cres on June 06, 2015, 07:17:56 AM ---maybe have an option where the backup overwrites previous backups but only for x times

this will prevent the backups taking up heaps of memory while still providing enough back-ups to switch back to

other than that, it's nice but such a thing really doesn't take a lot of work to make
hope people will make use of it

--- End quote ---
I considered that, actually. It's possible, though I don't know how it would save the timestamp since it currently saves it in the title of the archive. It could possibly just write it to a text file, but this seems less convenient for whenever it's needed.

Cres:

just make it save as n-th back-up and make it check how many backups exist. if it exceeds x, you make it delete the last one

Pure_:

Feedback:

* Conventions pls
* How is the user going to terminate your software without going into task manager? - Writing this in java so that it can be implemented into the server as a library may be a better idea to prevent this.
* Note: that since your backing up isnt async, the delay wont actually be 30mins but a little greater
Your logic for waiting is not very pretty, you have two reasonable options:

1) Simplistic - note how it trims your logic by a lot

--- Code: C# ---... while (Running) {  Thread.Sleep(backupDelay); // ie 30 mins would be 30 * 60 * 1000  Backup();} ...
2) Timer - this specific implementation runs on a background thread so it wont lock up your application either (note other classes called Timer exist and may behave differently)
System.Threading.Timer - example[/url]

Pages: (1/2) >>>

Go to full version