-
Notifications
You must be signed in to change notification settings - Fork 0
/
backup.sh
43 lines (37 loc) · 1.14 KB
/
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
date=$(date '+%Y-%m-%d-%H-%M')
fullbackup='/var/mariadb/backup'
incrbackup='/var/mariadb/increm'
archivepth='/var/mariadb/archive'
encryptkey='YOUR KEY TO ENCRYPT'
dbuser='YOUR DB USERNAME'
dbpass='YOUR DB PASSWORD'
if [ $1 = 'full' ]; then
rm -rf $fullbackup
mkdir -p $fullbackup
mariabackup --backup --user=$dbuser --password=$dbpass \
--target-dir=$fullbackup
mkdir -p $archivepth
filename=$date-full.tar.gz.ssl
tar -czf - $fullbackup | openssl enc \
-out $archivepth/$filename \
-e -aes256 \
-k $encryptkey
elif [ $1 = 'incr' ]; then
rm -rf $incrbackup
mkdir -p $incrbackup
mariabackup --backup --user=$dbuser --password=$dbpass \
--target-dir=$incrbackup \
--incremental-basedir=$fullbackup
mkdir -p $archivepth
filename=$date-incr.tar.gz.ssl
sudo tar - czf - $incrbackup | openssl enc \
-out $archivepth/$filename \
-e aes256 \
-k $encryptkey
fi
rclone sync $archivepth sftp:mariadb
for file in $archivepth/*.ssl; do
if [[ $file == *-incr* ]] && [[ $file |= *$(date '+%Y-%m-%d')*]]; then
rm $file
fi
done