-
Notifications
You must be signed in to change notification settings - Fork 3
/
backup.sh
43 lines (34 loc) · 968 Bytes
/
backup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/bash -e
##
# Log success message if log file exists
#
# $1 Backup name (eg. rancher)
# $2 Full backup path
#
function success {
log_file="/var/backup.log"
if [ -f "$log_file" ]; then
dir_size=`du -sh $2 | cut -f 1`
echo -e "$(date +"%s;%Y-%m-%d %H:%M:%S");$1;$dir_size;$2\n$(cat $log_file)" > $log_file
fi
}
##
# xtrabackup proxy
#
# $1 Backup name (eg. rancher)
# $2 Xtrabackup additional command args (eg. --compress)
#
backup_path="/mnt/backup/$1/$(date +'%Y/%m/%d/%s')"
mkdir -p "$backup_path"
echo "Backup start in: $backup_path"
`xtrabackup --target-dir=$backup_path --backup $2`
if [[ "$2" != *"incremental-basedir"* ]]; then
ln_backup_path="/mnt/backup/$1/latest-full"
rm -f "$ln_backup_path" || true
ln -s "$backup_path" "$ln_backup_path"
fi
ln_backup_path="/mnt/backup/$1/latest"
rm -f "$ln_backup_path" || true
ln -s "$backup_path" "$ln_backup_path"
success "$1" "$backup_path"
echo 'Backup complete'