From 527adc85555c126b5140d2ee55b10794137a7d36 Mon Sep 17 00:00:00 2001 From: Pijus Kamandulis Date: Thu, 17 Jan 2019 01:41:58 +0200 Subject: [PATCH] Create make-backup.sh --- backup/make-backup.sh | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 backup/make-backup.sh diff --git a/backup/make-backup.sh b/backup/make-backup.sh new file mode 100644 index 0000000..ec997d8 --- /dev/null +++ b/backup/make-backup.sh @@ -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