Browse Source

Add backup script

spaghetti 4 years ago
parent
commit
097c328172
2 changed files with 41 additions and 0 deletions
  1. 5
    0
      Backup/README.md
  2. 36
    0
      Backup/backup.sh

+ 5
- 0
Backup/README.md View File

@@ -0,0 +1,5 @@
1
+This backup script tries to achieve Time Machine-like functionality using rsync
2
+
3
+It is meant to be run by an hourly cronjob
4
+
5
+Backups in the backup directory will be named in the form of "YYYY-MM-DD-HHMMSS", with "current" always being a symlink to the latest backup

+ 36
- 0
Backup/backup.sh View File

@@ -0,0 +1,36 @@
1
+#! /bin/bash
2
+
3
+backup=/var/backup
4
+date=$(date "+%Y-%m-%d-%H%M%S")
5
+mysqlpw="AAAAAAAAAA"
6
+
7
+mkdir -p $backup/$date/www
8
+rsync -ax --delete --exclude='.git*' --exclude='misc/*' --link-dest=$backup/current/www/ /var/www/ $backup/$date/www/
9
+mysqldump --single-transaction --password="${mysqlpw}" gazelle | gzip -c > $backup/$date/gazelle.sql.gz
10
+
11
+rm $backup/current
12
+ln -s $backup/$date $backup/current
13
+
14
+# One backup per day for backups older than 12 hours
15
+hourlies=$(find $backup -maxdepth 1 -type d -mmin +720 | sort)
16
+day=0
17
+for i in $hourlies; do
18
+	rday=$(echo $i | awk -F '-' '{print $3}')
19
+	if [[ $rday = $day ]]; then
20
+		rm -r $i
21
+	else
22
+		day=$rday
23
+	fi
24
+done
25
+
26
+# One backup per month for backups older than two weeks
27
+monthlies=$(find $backup -maxdepth 1 -type d -mtime +14 | sort)
28
+month=0
29
+for i in $monthlies; do
30
+	rmonth=$(echo $i | awk -F '-' '{print $2}')
31
+	if [[ $rmonth = $month ]]; then
32
+		rm -r $i
33
+	else
34
+		month=$rmonth
35
+	fi
36
+done

Loading…
Cancel
Save