]> git.pond.sub.org Git - empserver/blob - scripts/backup
Make: Get SHELL from Autoconf
[empserver] / scripts / backup
1 #!/bin/sh -e
2 # Backup script to be run from pre_update_hook
3 # Written by Markus Armbruster, 2005-2012
4 # This script is in the public domain.
5
6 # Use: edit configuration variables below to taste, then set
7 #   pre_update_hook = /wherever/backup
8 # in econfig.
9
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!
14 #
15 # This script is as simple as possible, since failure cancels the
16 # update.
17
18 # Configuration
19
20 # How to name backups
21 #
22 # If you back up multiple games to the same directories, better change
23 # this to include a unique game name.
24 #
25 # Single name, keep just the last backup:
26 name=data
27 # Name with timestamp, keep all backups:
28 #name=data-`date +%Y-%m-%d-%H:%M`
29
30 # Where to store the backups on the local machine
31 #
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.
35 local_dir=../backup
36
37 # Copy backups to remote machine using SSH
38 #
39 # Don't copy (are you *sure* you want to be stupid?):
40 remote_host=
41 remote_dir=
42 email=
43 #
44 # Do copy:
45 #remote_host=user@host
46 #remote_dir=empire/backup
47 #email=user@host
48
49 # End of configuration
50
51 # Create local backup directory if necessary
52 mkdir -p $local_dir
53
54 # Tar up the data directory
55 arc=$local_dir/$name.tar.gz
56 tar czf $arc .
57
58 # Copy the backup to another machine with SSH, in the background
59 #
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.
64 if [ "$remote_host" ]
65 then
66     nohup sh -c "scp -qBp '$arc' '$remote_host:$remote_dir' 2>&1 | mailx -s 'Empire backup save failed' '$email'" </dev/null >/dev/null 2>&1 &
67 fi
68 #
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 <"$arc"
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