|
@@ -3,11 +3,18 @@
|
|
|
#| Make backup of: |
|
|
|
#| -Web Pages (/var/www) |
|
|
|
#| -SQL Databases (MySQL or MariaDB) |
|
|
|
-#| -HTTP Server Configuration (/etc/nginx) |
|
|
|
-#| -Let's Encrypt Certificates (/etc/letsencrypt) |
|
|
|
-#| -Mail Mailboxes (/var/mail) |
|
|
|
+#| -HTTP Server Configuration (nginx) |
|
|
|
+#| -Let's Encrypt Certificates |
|
|
|
#| -Home Directory (/home) |
|
|
|
-#| -GOGS Git Repository (/opt/gogs) |
|
|
|
+#| -GOGS Git Repository |
|
|
|
+#| -Mail Mailboxes (/var/mail) |
|
|
|
+#| -PostFix MTA Configuration (SMTP mail server) |
|
|
|
+#| -Dovecot MDA Configuration (POP3/IMAP server) |
|
|
|
+#| -OpenDKIM Configuration (Anti email Spoofing) |
|
|
|
+#| -SPF Configuration (Anti email Spoofing) |
|
|
|
+#| -OpenDMARC Configuration (Anti email Spoofing) |
|
|
|
+#| -Amavis Configuration (Antivirus) |
|
|
|
+#| -SPAM Assassin (AntiSPAM) |
|
|
|
#| Compressed with: |
|
|
|
#| -Gzip |
|
|
|
#| -Bzip2 |
|
|
@@ -19,12 +26,12 @@
|
|
|
#| HELP: backup-server -h |
|
|
|
#| |
|
|
|
#| Guzmán Castanedo (guzman@castanedo.es) |
|
|
|
-#| Version 2.0 (March 2018) |
|
|
|
+#| Version 2.1 (May 2018) |
|
|
|
#| Licence: GPL v3.0 -> https://www.gnu.org/licenses/gpl-3.0.en.html |
|
|
|
#\###################################################################/
|
|
|
|
|
|
function usage {
|
|
|
- printf "%s Version 2.0\n" $(basename $0)
|
|
|
+ printf "%s Version 2.1\n" $(basename $0)
|
|
|
printf "Usage: %s [options]... -z|-j|-J|-7 [backupdir]\n" $(basename $0)
|
|
|
printf "Make a encrypted backup of a server compressed with: \n"
|
|
|
printf "\t·Gzip (tar.gz or tar.gz.gpg)\n"
|
|
@@ -37,8 +44,9 @@ function usage {
|
|
|
printf "\t\tDefault: %s\n" $backupDir
|
|
|
printf "Backup Options:\n"
|
|
|
printf "\t-p, --prefix name: prefix for the name of the backup\n"
|
|
|
- printf "\t\tDefault: %s\n" $backupPrefix
|
|
|
- printf "\t--no-postfix: disable the postfi: the full name will be the prefix\n"
|
|
|
+ printf "\t\tDefault: backup-'hostname'(%s)\n" $backupPrefix
|
|
|
+ printf "\t--postfix name: postfix for the name of the backup.\n"
|
|
|
+ printf "\t\tTo unset default postfix: --postfix \"\"\n"
|
|
|
printf "\t\tDefault: prefix-yyyy-mm-dd(date)-XXXXXX(random)\n"
|
|
|
printf "\t--no-remove: no remove old files\n"
|
|
|
printf "\t\tDefault: false\n"
|
|
@@ -110,8 +118,69 @@ function usage {
|
|
|
printf "\t--no-gogs: disable gogs backup\n"
|
|
|
printf "\t\tDefault: %s\n" $noGogs
|
|
|
printf "\n"
|
|
|
+ printf "Postfix Options:\n"
|
|
|
+ printf "\t--postfix-dir dir: set Postfix configuration directory to backup\n"
|
|
|
+ printf "\t\tDefault: %s\n" $postfixDir
|
|
|
+ printf "\t--no-postfix: disable Postfix backup\n"
|
|
|
+ printf "\t\tDefault: %s\n" $noPostfix
|
|
|
+ printf "\n"
|
|
|
+ printf "Dovecot Options:\n"
|
|
|
+ printf "\t--dovecot-dir dir: set Dovecot configuration directory to backup\n"
|
|
|
+ printf "\t\tDefault: %s\n" $dovecotDir
|
|
|
+ printf "\t--no-dovecot: disable Dovecot backup\n"
|
|
|
+ printf "\t\tDefault: %s\n" $noDovecot
|
|
|
+ printf "\n"
|
|
|
+ printf "OpenDKIM Options:\n"
|
|
|
+ printf "\t--opendkim-conf file: set OpenDKIM configuration file to backup\n"
|
|
|
+ printf "\t\tDefault: %s\n" $openDKIMConf
|
|
|
+ printf "\t--opendkim-default file: set OpenDKIM socket configuration file to backup\n"
|
|
|
+ printf "\t\tDefault: %s\n" $openDKIMDefault
|
|
|
+ printf "\t--opendkim-keys dir: set OpenDKIM keys dir to backup\n"
|
|
|
+ printf "\t\tDefault: %s\n" $openDKIMKeys
|
|
|
+ printf "\t--no-opendkim: disable OpenDKIM backup\n"
|
|
|
+ printf "\t\tDefault: %s\n" $noOpenDKIM
|
|
|
+ printf "\n"
|
|
|
+ printf "SPF Options:\n"
|
|
|
+ printf "\t--spf-dir dir: set SPF configuration directory to backup\n"
|
|
|
+ printf "\t\tDefault: %s\n" $spfDir
|
|
|
+ printf "\t--no-spf: disable SPF backup\n"
|
|
|
+ printf "\t\tDefault: %s\n" $noSPF
|
|
|
+ printf "\n"
|
|
|
+ printf "OpenDMARC Options:\n"
|
|
|
+ printf "\t--opendmarc-conf file: set OpenDMARC configuration file to backup\n"
|
|
|
+ printf "\t\tDefault: %s\n" $openDMARCConf
|
|
|
+ printf "\t--opendmarc-default file: set OpenDMARC socket configuration file to backup\n"
|
|
|
+ printf "\t\tDefault: %s\n" $openDMARCDefault
|
|
|
+ printf "\t--no-opendmarc: disable OpenDMARC backup\n"
|
|
|
+ printf "\t\tDefault: %s\n" $noOpenDMARC
|
|
|
+ printf "\n"
|
|
|
+ printf "Amavis Options:\n"
|
|
|
+ printf "\t--amavis-dir dir: set Amavis configuration directory to backup\n"
|
|
|
+ printf "\t\tDefault: %s\n" $amavisDir
|
|
|
+ printf "\t--no-amavis: disable Amavis backup\n"
|
|
|
+ printf "\t\tDefault: %s\n" $noAmavis
|
|
|
+ printf "\n"
|
|
|
+ printf "SPAM Assassin Options:\n"
|
|
|
+ printf "\t--spamassassin-dir dir: set SPAM Assassin configuration directory to backup\n"
|
|
|
+ printf "\t\tDefault: %s\n" $spamAssassinDir
|
|
|
+ printf "\t--no-spamassassin: disable SPAM Assassin backup\n"
|
|
|
+ printf "\t\tDefault: %s\n" $noSpamAssassin
|
|
|
+ printf "\n"
|
|
|
printf "Other Options:\n"
|
|
|
+ printf "\t--no-sha512: not calculate SHA512 hash (to check integrity)\n"
|
|
|
printf "\t-h, --help: shows this message and exit\n"
|
|
|
+ printf "\n"
|
|
|
+ printf "Examples:\n"
|
|
|
+ printf "\t·%s --xz -k ABCDEFG -p backup-example.com --no-sql /var/backup\n" $(basename $0)
|
|
|
+ printf "\t\tMake a backup in \"/var/backup\" compressed with XZ and encrypted with GPG2\n"
|
|
|
+ printf "\t\tPublic Key (\"backup-example.com-2018-03-19-a1b2c3.tar.xz.gpg\")\n"
|
|
|
+ printf "\t\tDisable SQL backup\n"
|
|
|
+ printf "\t·%s -7 --7z-password 7zpass --sql-user root --sql-password toor /var/www/backup\n" $(basename $0)
|
|
|
+ printf "\t\tMake a backup in \"/var/www/backup\" compressed with 7Zip and encrypted\n"
|
|
|
+ printf "\t\t(\"backup-'hostname'-2018-03-19-abcdef.7z\")\n"
|
|
|
+ printf "\t·%s -z --no-encryption --no-sql /var/backup\n" $(basename $0)
|
|
|
+ printf "\t\tMake a backup in \"/var/backup\" compressed with GZip and not encrypted\n"
|
|
|
+ printf "\t\t(\"backup-'hostname'-2018-03-19-qwerty.tar.gz\")\n"
|
|
|
}
|
|
|
|
|
|
function makep7zip {
|
|
@@ -123,10 +192,10 @@ function makep7zip {
|
|
|
if [ $noEncryption = true ];then
|
|
|
encrypt7z=""
|
|
|
fi
|
|
|
- printf "Backup File (7z):\t%s\n" $backupOutput
|
|
|
+ printf "Backup File:\t%s\n" $backupOutput
|
|
|
|
|
|
#Copy webpages code (except backup and main/public)
|
|
|
- if [ $noWeb = false ] && [ -d $webDir ];then
|
|
|
+ if [ $noWeb = false ];then
|
|
|
printf "Compressing:\t%s\n" $webDir
|
|
|
tempfile=$(mktemp -t exclude-XXX)
|
|
|
echo "www/backup" > $tempfile
|
|
@@ -139,7 +208,7 @@ function makep7zip {
|
|
|
fi
|
|
|
|
|
|
#Copy MySQL databases (mysqldump)
|
|
|
- if [ $noSql = false ] && [ ! -z $mysqluser ] && [ ! -z $mysqlpass ] && [ -x "$(which mysql)" ] && [ -x "$(which mysqldump)" ]; then
|
|
|
+ if [ $noSql = false ]; then
|
|
|
list=$(mysql -u $mysqluser -p$mysqlpass -e "show DATABASES;")
|
|
|
#Parse databases expect information_schema & performance_schema
|
|
|
for database in $list; do
|
|
@@ -161,7 +230,7 @@ function makep7zip {
|
|
|
fi
|
|
|
|
|
|
#Copy nginx configuration (sites-available)
|
|
|
- if [ $noNginx = false ] && [ -d $nginxDir ];then
|
|
|
+ if [ $noNginx = false ];then
|
|
|
printf "Compressing:\t%s\n" $nginxDir
|
|
|
7z a -t7z -mx=9 $encrypt7z $backupOutput $nginxDir > /dev/null
|
|
|
if [ $? != 0 ];then
|
|
@@ -170,7 +239,7 @@ function makep7zip {
|
|
|
fi
|
|
|
|
|
|
#Copy Email (this could be heavy in the future)
|
|
|
- if [ $noMail = false ] && [ -d $mailDir ];then
|
|
|
+ if [ $noMail = false ];then
|
|
|
printf "Compressing:\t%s\n" $mailDir
|
|
|
7z a -t7z -mx=9 $encrypt7z $backupOutput $mailDir > /dev/null
|
|
|
#tar -c -zf - $mailDir | 7z a -t7z -mx=9 -p$pass7z -mhe $backupOutput -simail.tar.gz > /dev/null
|
|
@@ -180,7 +249,7 @@ function makep7zip {
|
|
|
fi
|
|
|
|
|
|
#Copy Certificates (LetsEncrypt)
|
|
|
- if [ $noLetsencrypt = false ] && [ -d $letsencryptDir ];then
|
|
|
+ if [ $noLetsencrypt = false ];then
|
|
|
printf "Compressing:\t%s\n" $letsencryptDir
|
|
|
7z a -t7z -mx=9 $encrypt7z $backupOutput $letsEncryptDir > /dev/null
|
|
|
if [ $? != 0 ];then
|
|
@@ -189,7 +258,7 @@ function makep7zip {
|
|
|
fi
|
|
|
|
|
|
#Copy /home
|
|
|
- if [ $noHome = false ] && [ -d $homeDir ];then
|
|
|
+ if [ $noHome = false ];then
|
|
|
printf "Compressing:\t%s\n" $homeDir
|
|
|
7z a -t7z -mx=9 $encrypt7z $backupOutput $homeDir > /dev/null
|
|
|
if [ $? != 0 ];then
|
|
@@ -198,13 +267,111 @@ function makep7zip {
|
|
|
fi
|
|
|
|
|
|
#Copy GOGS
|
|
|
- if [ $noGogs = false ] && [ -d $gogsDir ];then
|
|
|
+ if [ $noGogs = false ];then
|
|
|
printf "Compressing:\t%s\n" $gogsDir
|
|
|
7z a -t7z -mx=9 $encrypt7z $backupOutput $gogsDir > /dev/null
|
|
|
if [ $? != 0 ];then
|
|
|
printf "WARNING:\tError copying GOGS Repository (Continue)\n"
|
|
|
fi
|
|
|
fi
|
|
|
+
|
|
|
+ #Copy Postfix
|
|
|
+ if [ $noPostfix = false ] && [ -d $postfixDir ];then
|
|
|
+ printf "Compressing:\t%s\n" $postfixDir
|
|
|
+ 7z a -t7z -mx=9 $encrypt7z $backupOutput $postfixDir > /dev/null
|
|
|
+ if [ $? != 0 ];then
|
|
|
+ printf "WARNING:\tError copying Postfix configuration (Continue)\n"
|
|
|
+ fi
|
|
|
+ fi
|
|
|
+
|
|
|
+ #Copy Dovecot
|
|
|
+ if [ $noDovecot = false ];then
|
|
|
+ printf "Compressing:\t%s\n" $dovecotDir
|
|
|
+ 7z a -t7z -mx=9 $encrypt7z $backupOutput $dovecotDir > /dev/null
|
|
|
+ if [ $? != 0 ];then
|
|
|
+ printf "WARNING:\tError copying Dovecot configuration (Continue)\n"
|
|
|
+ fi
|
|
|
+ fi
|
|
|
+
|
|
|
+ #Copy OpenDKIM
|
|
|
+ if [ $noOpenDKIM = false ];then
|
|
|
+ if [ -f $openDKIMConf ];then
|
|
|
+ printf "Compressing:\t%s\n" $openDKIMConf
|
|
|
+ 7z a -t7z -mx=9 $encrypt7z $backupOutput $openDKIMConf > /dev/null
|
|
|
+ if [ $? != 0 ];then
|
|
|
+ printf "WARNING:\tError copying OpenDKIM configuration (Continue)\n"
|
|
|
+ fi
|
|
|
+ else
|
|
|
+ printf "WARNING:\tFile %s not exist\n" $openDKIMConf
|
|
|
+ fi
|
|
|
+ if [ -f $openDKIMDefault ];then
|
|
|
+ printf "Compressing:\t%s\n" $openDKIMDefault
|
|
|
+ 7z a -t7z -mx=9 $encrypt7z $backupOutput $openDKIMDefault > /dev/null
|
|
|
+ if [ $? != 0 ];then
|
|
|
+ printf "WARNING:\tError copying OpenDKIM sockets configuration (Continue)\n"
|
|
|
+ fi
|
|
|
+ else
|
|
|
+ printf "WARNING:\tFile %s not exist\n" $openDKIMDefault
|
|
|
+ fi
|
|
|
+ if [ -d $openDKIMKeys ];then
|
|
|
+ printf "Compressing:\t%s\n" $openDKIMKeys
|
|
|
+ 7z a -t7z -mx=9 $encrypt7z $backupOutput $openDKIMKeys > /dev/null
|
|
|
+ if [ $? != 0 ];then
|
|
|
+ printf "WARNING:\tError copying OpenDKIM keys (Continue)\n"
|
|
|
+ fi
|
|
|
+ else
|
|
|
+ printf "WARNING:\tDir %s not exist\n" $openDKIMKeys
|
|
|
+ fi
|
|
|
+ fi
|
|
|
+
|
|
|
+ #Copy SPF
|
|
|
+ if [ $noSPF = false ];then
|
|
|
+ printf "Compressing:\t%s\n" $spfDir
|
|
|
+ 7z a -t7z -mx=9 $encrypt7z $backupOutput $spfDir > /dev/null
|
|
|
+ if [ $? != 0 ];then
|
|
|
+ printf "WARNING:\tError copying Postfix configuration (Continue)\n"
|
|
|
+ fi
|
|
|
+ fi
|
|
|
+
|
|
|
+ #Copy OpenDMARC
|
|
|
+ if [ $noOpenDMARC = false ];then
|
|
|
+ if [ -f $openDMARCConf ];then
|
|
|
+ printf "Compressing:\t%s\n" $openDMARCConf
|
|
|
+ 7z a -t7z -mx=9 $encrypt7z $backupOutput $openDMARCConf > /dev/null
|
|
|
+ if [ $? != 0 ];then
|
|
|
+ printf "WARNING:\tError copying OpenDMARC configuration (Continue)\n"
|
|
|
+ fi
|
|
|
+ else
|
|
|
+ printf "WARNING:\tFile %s not exist\n" $openDMARCConf
|
|
|
+ fi
|
|
|
+ if [ -f $openDMARCDefault ];then
|
|
|
+ printf "Compressing:\t%s\n" $openDMARCDefault
|
|
|
+ 7z a -t7z -mx=9 $encrypt7z $backupOutput $openDMARCDefault > /dev/null
|
|
|
+ if [ $? != 0 ];then
|
|
|
+ printf "WARNING:\tError copying OpenDMARC sockets configuration (Continue)\n"
|
|
|
+ fi
|
|
|
+ else
|
|
|
+ printf "WARNING:\tFile %s not exist\n" $openDMARCDefault
|
|
|
+ fi
|
|
|
+ fi
|
|
|
+
|
|
|
+ #Copy Amavis
|
|
|
+ if [ $noAmavis = false ];then
|
|
|
+ printf "Compressing:\t%s\n" $amavisDir
|
|
|
+ 7z a -t7z -mx=9 $encrypt7z $backupOutput $amavisDir > /dev/null
|
|
|
+ if [ $? != 0 ];then
|
|
|
+ printf "WARNING:\tError copying Amavis configuration (Continue)\n"
|
|
|
+ fi
|
|
|
+ fi
|
|
|
+
|
|
|
+ #Copy SPAMAssassin
|
|
|
+ if [ $noSpamAssassin = false ];then
|
|
|
+ printf "Compressing:\t%s\n" $spamAssassinDir
|
|
|
+ 7z a -t7z -mx=9 $encrypt7z $backupOutput $spamAssassinDir > /dev/null
|
|
|
+ if [ $? != 0 ];then
|
|
|
+ printf "WARNING:\tError copying SPAM Assasin configuration (Continue)\n"
|
|
|
+ fi
|
|
|
+ fi
|
|
|
}
|
|
|
|
|
|
function makeTar {
|
|
@@ -212,7 +379,7 @@ function makeTar {
|
|
|
printf "Backup File:\t%s\n" $backupOutput
|
|
|
|
|
|
#Copy webpages code (except backup and main/public)
|
|
|
- if [ $noWeb = false ] && [ -d $webDir ];then
|
|
|
+ if [ $noWeb = false ];then
|
|
|
printf "Adding:\t%s\n" $webDir
|
|
|
tar -rf $tempOutput -C $(dirname $webDir) --exclude=www/backup --exclude=www/main/public $(basename $webDir) > /dev/null 2>&1
|
|
|
if [ $? != 0 ]; then
|
|
@@ -221,7 +388,7 @@ function makeTar {
|
|
|
fi
|
|
|
|
|
|
#Copy MySQL databases (mysqldump)
|
|
|
- if [ $noSql = false ] && [ ! -z $mysqluser ] && [ ! -z $mysqlpass ] && [ -x "$(which mysql)" ] && [ -x "$(which mysqldump)" ]; then
|
|
|
+ if [ $noSql = false ]; then
|
|
|
list=$(mysql -u $mysqluser -p$mysqlpass -e "show DATABASES;" 2> /dev/null)
|
|
|
mkdir /tmp/mysql
|
|
|
#Parse databases expect information_schema & performance_schema
|
|
@@ -251,7 +418,7 @@ function makeTar {
|
|
|
fi
|
|
|
|
|
|
#Copy nginx configuration (sites-available)
|
|
|
- if [ $noNginx = false ] && [ -d $nginxDir ];then
|
|
|
+ if [ $noNginx = false ];then
|
|
|
printf "Adding:\t%s\n" $nginxDir
|
|
|
tar -rf $tempOutput -C $(dirname $nginxDir) $(basename $nginxDir) > /dev/null 2>&1
|
|
|
if [ $? != 0 ];then
|
|
@@ -260,7 +427,7 @@ function makeTar {
|
|
|
fi
|
|
|
|
|
|
#Copy Email (this could be heavy in the future)
|
|
|
- if [ $noMail = false ] && [ -d $mailDir ];then
|
|
|
+ if [ $noMail = false ];then
|
|
|
printf "Adding:\t%s\n" $mailDir
|
|
|
tar -rf $tempOutput -C $(dirname $mailDir) $(basename $mailDir) > /dev/null 2>&1
|
|
|
if [ $? != 0 ];then
|
|
@@ -269,7 +436,7 @@ function makeTar {
|
|
|
fi
|
|
|
|
|
|
#Copy Certificates (LetsEncrypt)
|
|
|
- if [ $noLetsencrypt = false ] && [ -d $letsencryptDir ];then
|
|
|
+ if [ $noLetsencrypt = false ];then
|
|
|
printf "Adding:\t%s\n" $letsencryptDir
|
|
|
tar -rf $tempOutput -C $(dirname $letsencryptDir) $(basename $letsencryptDir) > /dev/null 2>&1
|
|
|
if [ $? != 0 ];then
|
|
@@ -278,7 +445,7 @@ function makeTar {
|
|
|
fi
|
|
|
|
|
|
#Copy /home
|
|
|
- if [ $noHome = false ] && [ -d $homeDir ];then
|
|
|
+ if [ $noHome = false ];then
|
|
|
printf "Adding:\t%s\n" $homeDir
|
|
|
tar -rf $tempOutput -C $(dirname $homeDir) $(basename $homeDir) > /dev/null 2>&1
|
|
|
if [ $? != 0 ];then
|
|
@@ -287,13 +454,111 @@ function makeTar {
|
|
|
fi
|
|
|
|
|
|
#Copy GOGS
|
|
|
- if [ $noGogs = false ] && [ -d $gogsDir ];then
|
|
|
- printf "Adding:\t/opt/gogs\n"
|
|
|
+ if [ $noGogs = false ];then
|
|
|
+ printf "Adding:\t%s\n" $gogsDir
|
|
|
tar -rf $tempOutput -C $(dirname $gogsDir) $(basename $gogsDir) > /dev/null 2>&1
|
|
|
if [ $? != 0 ];then
|
|
|
printf "WARNING:\tError copying GOGS Repository (Continue)\n"
|
|
|
fi
|
|
|
fi
|
|
|
+
|
|
|
+ #Copy Postfix
|
|
|
+ if [ $noPostfix = false ] && [ -d $postfixDir ];then
|
|
|
+ printf "Adding:\t%s\n" $postfixDir
|
|
|
+ tar -rf $tempOutput -C $(dirname $postfixDir) $(basename $postfixDir) > /dev/null 2>&1
|
|
|
+ if [ $? != 0 ];then
|
|
|
+ printf "WARNING:\tError copying Postfix configuration (Continue)\n"
|
|
|
+ fi
|
|
|
+ fi
|
|
|
+
|
|
|
+ #Copy Dovecot
|
|
|
+ if [ $noDovecot = false ];then
|
|
|
+ printf "Adding:\t%s\n" $dovecotDir
|
|
|
+ tar -rf $tempOutput -C $(dirname $dovecotDir) $(basename $dovecotDir) > /dev/null 2>&1
|
|
|
+ if [ $? != 0 ];then
|
|
|
+ printf "WARNING:\tError copying Dovecot configuration (Continue)\n"
|
|
|
+ fi
|
|
|
+ fi
|
|
|
+
|
|
|
+ #Copy OpenDKIM
|
|
|
+ if [ $noOpenDKIM = false ];then
|
|
|
+ if [ -f $openDKIMConf ];then
|
|
|
+ printf "Adding:\t%s\n" $openDKIMConf
|
|
|
+ tar -rf $tempOutput -C $(dirname $openDKIMConf) $(basename $openDKIMConf) > /dev/null 2>&1
|
|
|
+ if [ $? != 0 ];then
|
|
|
+ printf "WARNING:\tError copying OpenDKIM configuration (Continue)\n"
|
|
|
+ fi
|
|
|
+ else
|
|
|
+ printf "WARNING:\tFile %s not exist\n" $openDKIMConf
|
|
|
+ fi
|
|
|
+ if [ -f $openDKIMDefault ];then
|
|
|
+ printf "Adding:\t%s\n" $openDKIMDefault
|
|
|
+ tar -rf $tempOutput -C $(dirname $(dirname $openDKIMDefault)) $(basename $(dirname $openDKIMDefault))/$(basename $openDKIMDefault) > /dev/null 2>&1
|
|
|
+ if [ $? != 0 ];then
|
|
|
+ printf "WARNING:\tError copying OpenDKIM sockets configuration (Continue)\n"
|
|
|
+ fi
|
|
|
+ else
|
|
|
+ printf "WARNING:\tFile %s not exist\n" $openDKIMDefault
|
|
|
+ fi
|
|
|
+ if [ -d $openDKIMKeys ];then
|
|
|
+ printf "Adding:\t%s\n" $openDKIMKeys
|
|
|
+ tar -rf $tempOutput -C $(dirname $openDKIMKeys) $(basename $openDKIMKeys) > /dev/null 2>&1
|
|
|
+ if [ $? != 0 ];then
|
|
|
+ printf "WARNING:\tError copying OpenDKIM keys (Continue)\n"
|
|
|
+ fi
|
|
|
+ else
|
|
|
+ printf "WARNING:\tDir %s not exist\n" $openDKIMKeys
|
|
|
+ fi
|
|
|
+ fi
|
|
|
+
|
|
|
+ #Copy SPF
|
|
|
+ if [ $noSPF = false ];then
|
|
|
+ printf "Adding:\t%s\n" $spfDir
|
|
|
+ tar -rf $tempOutput -C $(dirname $spfDir) $(basename $spfDir) > /dev/null 2>&1
|
|
|
+ if [ $? != 0 ];then
|
|
|
+ printf "WARNING:\tError copying Postfix configuration (Continue)\n"
|
|
|
+ fi
|
|
|
+ fi
|
|
|
+
|
|
|
+ #Copy OpenDMARC
|
|
|
+ if [ $noOpenDMARC = false ];then
|
|
|
+ if [ -f $openDMARCConf ];then
|
|
|
+ printf "Adding:\t%s\n" $openDMARCConf
|
|
|
+ tar -rf $tempOutput -C $(dirname $openDMARCConf) $(basename $openDMARCConf) > /dev/null 2>&1
|
|
|
+ if [ $? != 0 ];then
|
|
|
+ printf "WARNING:\tError copying OpenDMARC configuration (Continue)\n"
|
|
|
+ fi
|
|
|
+ else
|
|
|
+ printf "WARNING:\tFile %s not exist\n" $openDMARCConf
|
|
|
+ fi
|
|
|
+ if [ -f $openDMARCDefault ];then
|
|
|
+ printf "Adding:\t%s\n" $openDMARCDefault
|
|
|
+ tar -rf $tempOutput -C $(dirname $(dirname $openDMARCDefault)) $(basename $(dirname $openDMARCDefault))/$(basename $openDMARCDefault) > /dev/null 2>&1
|
|
|
+ if [ $? != 0 ];then
|
|
|
+ printf "WARNING:\tError copying OpenDMARC sockets configuration (Continue)\n"
|
|
|
+ fi
|
|
|
+ else
|
|
|
+ printf "WARNING:\tFile %s not exist\n" $openDMARCDefault
|
|
|
+ fi
|
|
|
+ fi
|
|
|
+
|
|
|
+ #Copy Amavis
|
|
|
+ if [ $noAmavis = false ];then
|
|
|
+ printf "Adding:\t%s\n" $amavisDir
|
|
|
+ tar -rf $tempOutput -C $(dirname $amavisDir) $(basename $amavisDir) > /dev/null 2>&1
|
|
|
+ if [ $? != 0 ];then
|
|
|
+ printf "WARNING:\tError copying Amavis configuration (Continue)\n"
|
|
|
+ fi
|
|
|
+ fi
|
|
|
+
|
|
|
+ #Copy SPAMAssassin
|
|
|
+ if [ $noSpamAssassin = false ];then
|
|
|
+ printf "Adding:\t%s\n" $spamAssassinDir
|
|
|
+ tar -rf $tempOutput -C $(dirname $spamAssassinDir) $(basename $spamAssassinDir) > /dev/null 2>&1
|
|
|
+ if [ $? != 0 ];then
|
|
|
+ printf "WARNING:\tError copying SPAM Assasin configuration (Continue)\n"
|
|
|
+ fi
|
|
|
+ fi
|
|
|
}
|
|
|
|
|
|
function gzUnencrypted {
|
|
@@ -304,6 +569,7 @@ function gzUnencrypted {
|
|
|
exit 1
|
|
|
fi
|
|
|
rm $tempOutput
|
|
|
+ printf " done\n"
|
|
|
}
|
|
|
|
|
|
function gzEncrypted {
|
|
@@ -314,6 +580,7 @@ function gzEncrypted {
|
|
|
exit 1
|
|
|
fi
|
|
|
rm $tempOutput
|
|
|
+ printf " done\n"
|
|
|
}
|
|
|
|
|
|
function bz2Unencrypted {
|
|
@@ -324,6 +591,7 @@ function bz2Unencrypted {
|
|
|
exit 1
|
|
|
fi
|
|
|
rm $tempOutput
|
|
|
+ printf " done\n"
|
|
|
}
|
|
|
|
|
|
function bz2Encrypted {
|
|
@@ -334,6 +602,7 @@ function bz2Encrypted {
|
|
|
exit 1
|
|
|
fi
|
|
|
rm $tempOutput
|
|
|
+ printf " done\n"
|
|
|
}
|
|
|
|
|
|
function xzUnencrypted {
|
|
@@ -344,6 +613,7 @@ function xzUnencrypted {
|
|
|
exit 1
|
|
|
fi
|
|
|
rm $tempOutput
|
|
|
+ printf " done\n"
|
|
|
}
|
|
|
|
|
|
function xzEncrypted {
|
|
@@ -354,6 +624,24 @@ function xzEncrypted {
|
|
|
exit 1
|
|
|
fi
|
|
|
rm $tempOutput
|
|
|
+ printf " done\n"
|
|
|
+}
|
|
|
+
|
|
|
+function makeSHA512 {
|
|
|
+ if [ ! -x $(which sha512sum) ]; then
|
|
|
+ printf "WARNING:\tsha512sum not installed\n"
|
|
|
+ sha512=false
|
|
|
+ fi
|
|
|
+ if [ $sha512 = true ]; then
|
|
|
+ printf "Calculating checksum (SHA512)..."
|
|
|
+ cd $backupDir > /dev/null 2>&1
|
|
|
+ sha512sum -b $(basename $backupOutput) > $backupOutput.sha512
|
|
|
+ #Permissions
|
|
|
+ chown $user:$group $backupOutput.sha512
|
|
|
+ chmod $permisionMask $backupOutput.sha512
|
|
|
+ cd - > /dev/null 2>&1
|
|
|
+ printf " done\n"
|
|
|
+ fi
|
|
|
}
|
|
|
|
|
|
function checkRoutes {
|
|
@@ -362,23 +650,66 @@ function checkRoutes {
|
|
|
usage
|
|
|
exit 1
|
|
|
fi
|
|
|
- if [ ! -d $webDir ];then
|
|
|
+ if [ $noWeb = false ] && [ ! -d $webDir ];then
|
|
|
printf "WARNING:\t%s don't exist (no backup)\n" $webDir
|
|
|
+ noWeb=true
|
|
|
fi
|
|
|
- if [ ! -d $nginxDir ];then
|
|
|
+ if [ $noNginx = false ] && [ ! -d $nginxDir ];then
|
|
|
printf "WARNING:\t%s don't exist (no backup)\n" $nginxDir
|
|
|
+ noNginx=true
|
|
|
fi
|
|
|
- if [ ! -d $letsencryptDir ];then
|
|
|
+ if [ $noLetsencrypt = false ] && [ ! -d $letsencryptDir ];then
|
|
|
printf "WARNING:\t%s don't exist (no backup)\n" $letsencryptDir
|
|
|
+ noLetsencrypt=true
|
|
|
fi
|
|
|
- if [ ! -d $mailDir ];then
|
|
|
+ if [ $noMail = false ] && [ ! -d $mailDir ];then
|
|
|
printf "WARNING:\t%s don't exist (no backup)\n" $mailDir
|
|
|
+ noMail=true
|
|
|
fi
|
|
|
- if [ ! -d $homeDir ];then
|
|
|
+ if [ $noHome = false ] && [ ! -d $homeDir ];then
|
|
|
printf "WARNING:\t%s don't exist (no backup)\n" $homeDir
|
|
|
+ noHome=true
|
|
|
fi
|
|
|
- if [ ! -d $gogsDir ];then
|
|
|
+ if [ $noGogs = false ] && [ ! -d $gogsDir ];then
|
|
|
printf "WARNING:\t%s don't exist (no backup)\n" $gogsDir
|
|
|
+ noGogs=true
|
|
|
+ fi
|
|
|
+ if [ $noPostfix = false ] && [ ! -d $postfixDir ];then
|
|
|
+ printf "WARNING:\t%s don't exist (no backup)\n" $postfixDir
|
|
|
+ noPostfix=true
|
|
|
+ fi
|
|
|
+ if [ $noDovecot = false ] && [ ! -d $dovecotDir ];then
|
|
|
+ printf "WARNING:\t%s don't exist (no backup)\n" $dovecotDir
|
|
|
+ noDovecot=true
|
|
|
+ fi
|
|
|
+ # No noOpenDKIM=true, to make a parcial copy
|
|
|
+ if [ $noOpenDKIM = false ] && [ ! -f $openDKIMConf ];then
|
|
|
+ printf "WARNING:\t%s don't exist (no backup)\n" $openDKIMConf
|
|
|
+ fi
|
|
|
+ if [ $noOpenDKIM = false ] && [ ! -f $openDKIMDefault ];then
|
|
|
+ printf "WARNING:\t%s don't exist (no backup)\n" $openDKIMDefault
|
|
|
+ fi
|
|
|
+ if [ $noOpenDKIM = false ] && [ ! -d $openDKIMKeys ];then
|
|
|
+ printf "WARNING:\t%s don't exist (no backup)\n" $openDKIMKeys
|
|
|
+ fi
|
|
|
+ if [ $noSPF = false ] && [ ! -d $spfDir ];then
|
|
|
+ printf "WARNING:\t%s don't exist (no backup)\n" $spfDir
|
|
|
+ noSpf=true
|
|
|
+ fi
|
|
|
+ # No noOpenDMARC=true, to make a parcial copy
|
|
|
+ if [ $noOpenDMARC = false ] && [ ! -f $openDMARCConf ];then
|
|
|
+ printf "WARNING:\t%s don't exist (no backup)\n" $openDMARCConf
|
|
|
+ fi
|
|
|
+ if [ $noOpenDMARC = false ] && [ ! -f $openDMARCDefault ];then
|
|
|
+ printf "WARNING:\t%s don't exist (no backup)\n" $openDMARCDefault
|
|
|
+ fi
|
|
|
+ if [ $noAmavis = false ] && [ ! -d $amavisDir ];then
|
|
|
+ printf "WARNING:\t%s don't exist (no backup)\n" $amavisDir
|
|
|
+ noAmavis=true
|
|
|
+ fi
|
|
|
+ if [ $noSpamAssassin = false ] && [ ! -d $spamAssassinDir ];then
|
|
|
+ printf "WARNING:\t%s don't exist (no backup)\n" $spamAssassinDir
|
|
|
+ noSpamAssassin=true
|
|
|
fi
|
|
|
}
|
|
|
|
|
@@ -416,6 +747,10 @@ function checkMethod {
|
|
|
|
|
|
function checkSqlAuth {
|
|
|
if [ $noSql = false ];then
|
|
|
+ if [ ! -x "$(which mysql)" ] || [ ! -x "$(which mysqldump)" ];then
|
|
|
+ printf "WARNING:\tmysql or/and mysqldump Not installed\n"
|
|
|
+ noSql=true
|
|
|
+ fi
|
|
|
if [ -z $mysqluser ] || [ -z $mysqlpass ]; then
|
|
|
printf "WARNING:\tSQL User/Password not set: continue without SQL backup (type \"%s -h\" for help)\n" $(basename $0)
|
|
|
noSql=true
|
|
@@ -436,7 +771,7 @@ mysqlpass=""
|
|
|
keyID=""
|
|
|
pass7z=""
|
|
|
backupDir=/var/www/backup
|
|
|
-backupPrefix="backup-castanedo.es"
|
|
|
+backupPrefix="backup-"$(hostname)
|
|
|
backupPostfix=-$(date +"%Y-%m-%d")-$(cat /dev/urandom | tr -dc 'a-z0-9' | fold -w 6 | head -n 1)
|
|
|
deleteDays="15"
|
|
|
user="www-data"
|
|
@@ -449,6 +784,16 @@ mailDir="/var/mail"
|
|
|
letsencryptDir="/etc/letsencrypt"
|
|
|
homeDir="/home"
|
|
|
gogsDir="/opt/gogs"
|
|
|
+postfixDir="/etc/postfix"
|
|
|
+dovecotDir="/etc/dovecot"
|
|
|
+openDKIMConf="/etc/opendkim.conf"
|
|
|
+openDKIMDefault="/etc/default/opendkim"
|
|
|
+openDKIMKeys="/etc/dkimkeys"
|
|
|
+spfDir="/etc/postfix-policyd-spf-python"
|
|
|
+openDMARCConf="/etc/opendmarc.conf"
|
|
|
+openDMARCDefault="/etc/default/opendmarc"
|
|
|
+amavisDir="/etc/amavis"
|
|
|
+spamAssassinDir="/etc/spamassassin"
|
|
|
|
|
|
#Control Variables
|
|
|
noEncryption=false
|
|
@@ -466,9 +811,17 @@ noMail=false
|
|
|
noLetsencrypt=false
|
|
|
noHome=false
|
|
|
noGogs=false
|
|
|
+noPostfix=false
|
|
|
+noDovecot=false
|
|
|
+noOpenDKIM=false
|
|
|
+noSPF=false
|
|
|
+noOpenDMARC=false
|
|
|
+noAmavis=false
|
|
|
+noSpamAssassin=false
|
|
|
+sha512=true
|
|
|
|
|
|
#Parse args
|
|
|
-TEMP=$(getopt -q -o zjJ7p:u:g:k:h --longoptions gzip,bzip2,xz,7zip,prefix:,no-postfix,no-remove,remove-days:,user:,group:,permision-mask:,key-id:,no-encryption,7z-password:,web-dir:,no-web,no-sql,sql-user:,sql-password:,nginx-dir:,no-nginx,letsencrypt-dir:,no-letsencrypt,mail-dir:,no-mail,home-dir:,no-home,gogs-dir:,no-gogs,help --name $(basename $0) -- $@)
|
|
|
+TEMP=$(getopt -q -o zjJ7p:u:g:k:h --longoptions gzip,bzip2,xz,7zip,prefix:,postfix:,no-remove,remove-days:,user:,group:,permision-mask:,key-id:,no-encryption,7z-password:,web-dir:,no-web,no-sql,sql-user:,sql-password:,nginx-dir:,no-nginx,letsencrypt-dir:,no-letsencrypt,mail-dir:,no-mail,home-dir:,no-home,gogs-dir:,no-gogs,postfix-dir:,no-postfix,dovecot-dir:,no-dovecot,opendkim-conf:,opendkim-default:,opendkim-keys:,no-opendkim,spf-dir:,no-spf,opendmarc-conf:,opendmarc-default:,no-opendmarc,amavis-dir:,no-amavis,spamassassin-dir:,no-spamassassin,no-sha512,help --name $(basename $0) -- $@)
|
|
|
eval set -- $TEMP
|
|
|
unset TEMP
|
|
|
while true; do
|
|
@@ -529,9 +882,9 @@ while true; do
|
|
|
backupPrefix=$2
|
|
|
shift 2
|
|
|
;;
|
|
|
- --no-postfix)
|
|
|
- backupPostfix=""
|
|
|
- shift
|
|
|
+ --postfix)
|
|
|
+ backupPostfix=$2
|
|
|
+ shift 2
|
|
|
;;
|
|
|
--no-remove)
|
|
|
removeOld=false
|
|
@@ -642,6 +995,78 @@ while true; do
|
|
|
noGogs=true
|
|
|
shift
|
|
|
;;
|
|
|
+ --postfix-dir)
|
|
|
+ postfixDir=$2
|
|
|
+ shift 2
|
|
|
+ ;;
|
|
|
+ --no-postfix)
|
|
|
+ noPostfix=true
|
|
|
+ shift
|
|
|
+ ;;
|
|
|
+ --dovecot-dir)
|
|
|
+ dovecotDir=$2
|
|
|
+ shift 2
|
|
|
+ ;;
|
|
|
+ --no-dovecot)
|
|
|
+ noDovecot=true
|
|
|
+ shift
|
|
|
+ ;;
|
|
|
+ --opendkim-conf)
|
|
|
+ openDKIMConf=$2
|
|
|
+ shift 2
|
|
|
+ ;;
|
|
|
+ --opendkim-default)
|
|
|
+ openDKIMDefault=$2
|
|
|
+ shift 2
|
|
|
+ ;;
|
|
|
+ --opendkim-keys)
|
|
|
+ openDKIMKeys=$2
|
|
|
+ shift 2
|
|
|
+ ;;
|
|
|
+ --no-opendkim)
|
|
|
+ noOpenDKIM=true
|
|
|
+ shift
|
|
|
+ ;;
|
|
|
+ --spf-dir)
|
|
|
+ spfDir=$2
|
|
|
+ shift 2
|
|
|
+ ;;
|
|
|
+ --no-spf)
|
|
|
+ noSPF=true
|
|
|
+ shift
|
|
|
+ ;;
|
|
|
+ --opendmarc-conf)
|
|
|
+ openDMARCConf=$2
|
|
|
+ shift 2
|
|
|
+ ;;
|
|
|
+ --opendmarc-default)
|
|
|
+ openDMARCDefault=$2
|
|
|
+ shift 2
|
|
|
+ ;;
|
|
|
+ --no-opendmarc)
|
|
|
+ noOpenDMARC=true
|
|
|
+ shift
|
|
|
+ ;;
|
|
|
+ --amavis-dir)
|
|
|
+ amavisDir=$2
|
|
|
+ shift 2
|
|
|
+ ;;
|
|
|
+ --no-amavis)
|
|
|
+ noAmavis=true
|
|
|
+ shift
|
|
|
+ ;;
|
|
|
+ --spamassassin-dir)
|
|
|
+ spamAssassinDir=$2
|
|
|
+ shift 2
|
|
|
+ ;;
|
|
|
+ --no-spamassassin)
|
|
|
+ noSpamAssassin=true
|
|
|
+ shift
|
|
|
+ ;;
|
|
|
+ --no-sha512)
|
|
|
+ sha512=false
|
|
|
+ shift
|
|
|
+ ;;
|
|
|
-h|--help)
|
|
|
usage
|
|
|
exit 0
|
|
@@ -719,22 +1144,28 @@ else
|
|
|
fi
|
|
|
fi
|
|
|
|
|
|
+#Make SHA512
|
|
|
+if [ $sha512 = true ]; then
|
|
|
+ makeSHA512
|
|
|
+fi
|
|
|
+
|
|
|
#Permissions
|
|
|
chown $user:$group $backupOutput
|
|
|
chmod $permisionMask $backupOutput
|
|
|
|
|
|
#Remove files older than 15 days
|
|
|
if [ $removeOld = true ];then
|
|
|
- printf "\nEliminando backups antiguos (+15 dias)\n"
|
|
|
+ printf "Deletting old backups (+15 days)..."
|
|
|
find $backupDir -mindepth 1 -maxdepth 1 -mtime +$deleteDays -type f -iname $backupPrefix*$ext -delete
|
|
|
if [ $? != 0 ];then
|
|
|
- printf "WARNING:\tError eliminando backup's antiguos (%s dias)\n" $deleteDays
|
|
|
+ printf "\nWARNING:\tImposible to delete old backups (+%s days)\n" $deleteDays
|
|
|
fi
|
|
|
+ printf " done\n"
|
|
|
fi
|
|
|
|
|
|
#End
|
|
|
finalTime=$(date +"%s")
|
|
|
printf "\n"
|
|
|
echo "------------------------------------------------"
|
|
|
-printf "Backup completado con exito en %s segundos :)\n" $((finalTime-startTime))
|
|
|
+printf "Backup completed successfully in %s seconds :)\n" $((finalTime-startTime))
|
|
|
echo "------------------------------------------------"
|