Create make-backup.sh

This commit is contained in:
Pijus Kamandulis 2019-01-17 01:41:58 +02:00 committed by GitHub
parent eba6b037cc
commit 527adc8555
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

32
backup/make-backup.sh Normal file
View File

@ -0,0 +1,32 @@
#!/bin/bash
DATE=$(date +"%d-%m-%Y")
BACKUP_DIR='/home/backuper/backups'
DIRS_TO_BACKUP=(
# Mail
'/etc/;postfix' # postfix configs
'/etc/;dovecot' # dovecot configs
'/var/;mail' # emails
# Web
'/etc/;nginx' # nginx configs
'/var/;www' # websites
)
# Setup
mkdir -p $BACKUP_DIR/mysql
# Backup directories
for i in "${DIRS_TO_BACKUP[@]}"
do
conf=(${i//;/ })
echo ${conf[0]}
echo ${conf[1]}
tar -zcvf $BACKUP_DIR/${conf[1]}-$DATE.tgz -C ${conf[0]} ${conf[1]}
done
# SQL
mysql -N -e 'show databases' | while read dbname;
do
mysqldump --complete-insert --routines --triggers --single-transaction "$dbname" > $BACKUP_DIR/mysql/"$dbname".sql;
done
tar -zcvf $BACKUP_DIR/mysql-$DATE.tgz -C $BACKUP_DIR/ mysql
rm -rf $BACKUP_DIR/mysql