2 # Backup script to be run from pre_update_hook
3 # Written by Markus Armbruster, 2005
4 # This script is in the public domain.
6 # Use: edit configuration variables below to taste, then set
7 # pre_update_hook = /wherever/backup
10 # Rules when running as pre_update_hook:
11 # Data directory is working directory.
12 # stdin, stdout, stderr are redirected to /dev/null
13 # Exit code other than zero cancels update!
15 # This script is as simple as possible, since failure cancels the
22 # If you back up multiple games to the same directories, better change
23 # this to include a unique game name.
25 # Single name, keep just the last backup:
27 # Name with timestamp, keep all backups:
28 #name=data-`date +%Y-%m-%d-%H:%M`
30 # Where to store the backups on the local machine
32 # Storing backups on the same machine is stupid, and on the same file
33 # system is criminally stupid, so you better change this, unless you
34 # copy them to another machine.
37 # Copy backups to remote machine using SSH
39 # Don't copy (are you *sure* you want to be stupid?):
45 #remote_host=user@host
46 #remote_dir=empire/backup
49 # End of configuration
51 # Create local backup directory if necessary
54 # Tar up the data directory
55 tgz=$local_dir/$name.tar.gz
58 # Copy the backup to another machine with SSH, in the background
60 # The obvious method requires a key that is not protected by a
61 # passphrase. Trusting such keys remotely is usually a bad idea, but
62 # it might be tolerable if a special user runs the server, and that
63 # user's privileges are carefully limited.
66 nohup sh -c "scp -qBp '$tgz' '$remote_host:$remote_dir' 2>&1 | mail -e -s 'Empire backup save failed' '$email'" </dev/null >/dev/null 2>&1 &
69 # A more secure alternative is to replace the scp command by something like
70 # ssh -q -T -o BatchMode=yes -o IdentitiesOnly=yes -i "$HOME/.ssh/empire_id_rsa" $remote_host <"$tgz"
71 # where $HOME/.ssh/empire_id_rsa contains a private key specifically
72 # created for Empire backup, without a passphrase, and authorized_keys
73 # on $remote_host contains the matching public key prepended by
74 # command="cat >empire/backup/data-`/bin/date +%Y-%m-%d-%H:%M`.tar.gz",no-pty,no-port-forwarding