-
Notifications
You must be signed in to change notification settings - Fork 0
/
backup
executable file
·38 lines (32 loc) · 903 Bytes
/
backup
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
#!/bin/sh
parse_user() {
[ "$1" ] && USER="$1" || USER="root"
[ "$2" ] && PASS="-p$2" || PASS=""
}
parse_host() {
[ "$1" ] && HOST="$1" || HOST="mysql"
[ "$2" ] && PORT="-P$2" || PORT=""
}
backup_profile() {
parse_user $(echo "$1" | sed 's|:| |g')
parse_host $(echo "$2" | sed 's|:| |g')
if [ "$3" ]; then
DATABASE=$3
NAME="$HOST-$DATABASE.sql.gz"
else
DATABASE="--all-databases"
NAME="$HOST.sql.gz"
fi
echo "Saving $HOST ($DATABASE) to $NAME..."
time mysqldump -u$USER $PASS -h$HOST $PORT $MYSQLDUMP_OPTIONS $DATABASE | pigz -cf9 > "$NAME"
echo -e "Done! (exit code: $?)\n"
}
for profile in $PROFILES; do
backup_profile $(echo $profile | sed 's|[@/]| |g')
done
[ -e $RETENTION_PERIOD ] && rm -r $RETENTION_PERIOD
for i in $(seq $RETENTION_PERIOD -1 0); do
[ -e $i ] && mv $i $((i+1))
done
mkdir 0
mv *.gz 0/