Backup Scripts

Norganna's AddOns

목차

Backing up your SavedVariables with scripts

Example Scripts to help in backing up your saved variables on WINDOWS

Using 7zip

  • Install 7zip and note its install location
  • Navigate to your Warcraft install directory. In this example we will use C:\Program Files\World of Warcraft\
  • Create a new folder named whatever you desire. We will use WTFBackup
  • Open the folder you just created and create a new Text Document file
  • Open the text file you just created and add the following lines:


"C:\Program Files\7-Zip\7z" a -t7z WTF_Backup_%DATE:~4,2%-%DATE:~7,2%-%DATE:~-4%.7z -xr!*.lua.bak "C:\Program Files\World of Warcraft\WTF\" -m0=PPMd -mmem=500m

EXIT


  1. Now we need to edit this to work on your system. Be very carefull not to add or remove quote marks "
    • "C:\Program Files\7-Zip\7z" The path that you installed 7Zip in
    • WTF_Backup_ What do you want your backups to be titled No spaces are allowed use _ instead. And it must end with a _
  2. Now add the location of your WTF folder that contains all of your saved variables
    • "C:\Program Files\World of Warcraft\WTF\" Your World of Warcraft install path. In Vista this may be different than where teh game was installed, you will need to find where the WTF folder is located
  3. settings that you may tweak but are not necessary
    • -m0=PPMd The algorithm used for compression, PPMd is very fast and decent compression
    • -mmem=500m The amount of memory 7zip will use when compressing in megabytes
    • Now Save file as WhatEver.bat

When you click on the file it should now open a command prompt window and create a backup of all lua files in the WTF directory.

Cleaning Up Old Backups

Old backups can accumulate quickly, particularly if you have a script like the one mentioned above running on a daily basis. It is sometimes nice to include in your backup script a method of automatically cleaning up old backups. Quoted below is an example of a perl script that will delete any files in a specified path named according to a specific convention that are older than a specified amount of days. All those "specified"s can be set by editing the variables at the top of the file. Once you've set the script up as you wish, you can add it to your backup script by just adding:

[path to perl]\perl.exe TheScriptName.pl -q

to the end of the batch file you use to make your backups. (The -q is to make it skip all the confirmations, treating them as if you'd answered "y")

Note: This is a perl script, not a shell script. If you're not comfortable with perl and reading code to be certain you trust it, you should probably steer clear of this.

#!c:\perl64\bin\perl.exe
# Change the shebang to suit your needs.

# The path to the files you want to clean up.  The double backslash
# at the end is to preven the escaping of the closing '
my $path = 'C:\Games\WoW\WTF\Account\YourAccountName\SavedVariables\Backup\\';

# The naming pattern used for the files you want to clean up.  This
# must be a valid regular expression.
my $namepattern = "\d{8}-SVBackup.zip";

# Delete files older than this number of days.
my $agelimit = 7;

### End configurable options, do not edit below here	###
### unless you know what you're doing.			###
my $deleteall;
my @delete;
# Check for quietmode, which act as if all confirmations
# were answered with "y", for running with an automated
# backup script
my $quietmode;
if ($ARGV[0] =~ /-[qQ]/) {
	$quietmode = "true";
	print "Running in quiet mode\n";
}

# Go through the directory listing
foreach (glob($path . "*")) {
	# If files are found mathing your naming convention
	if (m/($namepattern)/) {
		$age = -M;
		# If the file is older than your specified age
		# and you haven't yet chosen to delete all remaining
		# files, offer to delete it.
		if (!$quietmode) {
			if ($age > $agelimit && !$deleteall) {
				print "$1 IS OVER 7 days old. Delete? (y/n/a)\n";
				my $choice = <STDIN>;
				chomp($choice);
				# If you choose yes, add the file to the queue.
				if ($choice =~ /[yY]/) {
					push(@delete,$_);
					print "$1 added to delete list\n";
				}
				# If you choose "all", add the file to the queue
				# and set up adding all remaining files to the
				# queue without prompting.
				elsif ($choice =~ /[aA]/) {
					push(@delete,$_);
					$deleteall = "true";
					print "$1 and all future files added to delete list\n";
				}
				# Otherwise skip it.  This could offer more
				# control (checking for invalid input and
				# reacting instead of defaulting to skip) but
				# I'm lazy.
				else {
					print "$1 skipped";
				}
			}
			# If you've chosen to delete all, add all remaining
			# files that are old enough to the queue and notify
			# you of each one.
			elsif ($age > $agelimit && $deleteall) {
				push(@delete,$_);
				print "$1 added to delete list\n";
			}
		}
		elsif ($age > $agelimit && $quietmode) {
			push(@delete,$_);
			print "$1 added to delete list\n";
		}
	}
}

# If you've chosen to delete at least one file
if (@delete && !$quietmode) {
	# Print off a list of files to be deleted for confirmation.
	print "The following files will be deleted:\n";
	foreach (@delete) {
		print "$1\n" if /($namepattern)/;
	}
	print "Continue? (y/n)\n";
	my $confirm = <STDIN>;
	chomp $confirm;
	print "\n";
	# If you choose to continue, delete the files and print
	# the number of the files deleted.
	if ($confirm =~ m/[yY]/) {
		my $result = unlink(@delete);
		print "$result files deleted.\n";
	}
	# Otherwise exit without doing anything.
	else {
		print "Exiting\n";
		exit 0;
	}
}
elsif (@delete && $quietmode) {
	my $result = unlink(@delete);
	print "$result files deleted.\n";
	exit 0;
}
# If there isn't at least one file to delete, notify you and exit.
else {
	print "Nothing to delete\n";
	exit 0;
}
개인 도구