1 |
#!/bin/bash
|
2 |
|
3 |
################################################################################
|
4 |
|
5 |
# This program is free software; you can redistribute it and/or modify it
|
6 |
# under the terms of the GNU General Public License as published by the
|
7 |
# Free Software Foundation; either version 2 of the License, or (at
|
8 |
# your option) any later version.
|
9 |
#
|
10 |
# This program is distributed in the hope that it will be useful, but
|
11 |
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13 |
# General Public License for more details.
|
14 |
#
|
15 |
# You should have received a copy of the GNU General Public License
|
16 |
# along with this program; if not, write to the Free Software Foundation,
|
17 |
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
18 |
|
19 |
# Unless you change the below variables, this script assumes:
|
20 |
# * Your backup path is /backup/ *and* the dir exists
|
21 |
# * hlds is installed in /usr/local/hlds/
|
22 |
# * The Linux user "cs" exists
|
23 |
# * The Linux user "cs" owns /usr/local/hlds/
|
24 |
# * The MySQL user is "wc3ft"
|
25 |
# * The MySQL database is "wc3ft"
|
26 |
# * The MySQL password is "**PASSWORD**"
|
27 |
# * The following files exist:
|
28 |
# - /home/cs/hlds_backup.sh
|
29 |
# - /home/cs/hlds_startup.sh
|
30 |
# - /etc/init.d/hlds
|
31 |
# - /etc/network/if-pre-up.d/iptables
|
32 |
# - /etc/fstab
|
33 |
# This script will keep two rotating backups from the most recent two days,
|
34 |
# located at: /backup/0/ and /backup/1/
|
35 |
# For non-leap years, the Jan. 1 backup will overwrite the Dec. 31 backup. All
|
36 |
# this means is that on Jan. 1, there will be a backup from Dec. 30 and one
|
37 |
# from Jan. 1. Dec. 31 is lost.
|
38 |
################################################################################
|
39 |
|
40 |
##### You can change these variables #####
|
41 |
BACKUP_PATH=/backup;
|
42 |
HLDS_PATH=/usr/local/hlds;
|
43 |
HLDS_USER=cs;
|
44 |
MYSQL_USER=wc3ft;
|
45 |
MYSQL_PASS=**PASSWORD**;
|
46 |
MYSQL_DB=wc3ft;
|
47 |
##### Don't change anything below here #####
|
48 |
|
49 |
EVENODD=$[ `date +%j` % 2 ];
|
50 |
|
51 |
# Remove files in directory we are about to use, or create it.
|
52 |
if [ -d /$BACKUP_PATH/$EVENODD/ ]; then
|
53 |
rm -rf $BACKUP_PATH/$EVENODD/*
|
54 |
else
|
55 |
mkdir $BACKUP_PATH/$EVENODD
|
56 |
# TODO: If this fails, exit script..
|
57 |
fi
|
58 |
|
59 |
/etc/init.d/hlds stop
|
60 |
|
61 |
nice -n 18 mysqldump --user=$MYSQL_USER --password=$MYSQL_PASS $MYSQL_DB > $BACKUP_PATH/$EVENODD/war3ft.sql
|
62 |
|
63 |
nice -n 18 cp --archive --parents $HLDS_PATH $BACKUP_PATH/$EVENODD/
|
64 |
nice -n 18 cp --archive --parents /home/$HLDS_USER/hlds_backup.sh $BACKUP_PATH/$EVENODD/
|
65 |
nice -n 18 cp --archive --parents /home/$HLDS_USER/hlds_startup.sh $BACKUP_PATH/$EVENODD/
|
66 |
nice -n 18 cp --archive --parents /etc/init.d/hlds $BACKUP_PATH/$EVENODD/
|
67 |
nice -n 18 cp --archive --parents /etc/network/if-pre-up.d/iptables $BACKUP_PATH/$EVENODD/
|
68 |
nice -n 18 cp --archive --parents /etc/fstab $BACKUP_PATH/$EVENODD/
|
69 |
|
70 |
nice -n 18 crontab -l > $BACKUP_PATH/$EVENODD/crontab.txt
|
71 |
|
72 |
/etc/init.d/hlds start
|