|
@@ -56,6 +56,9 @@ function usage {
|
|
printf "\t\tDefault: %s\n" $group
|
|
printf "\t\tDefault: %s\n" $group
|
|
printf "\t--permision-mask number: octal mask to set accesss permision of the backup\n"
|
|
printf "\t--permision-mask number: octal mask to set accesss permision of the backup\n"
|
|
printf "\t\tDefault: %s\n" $permisionMask
|
|
printf "\t\tDefault: %s\n" $permisionMask
|
|
|
|
+ printf "\t-e, --exclude file1[,file2,[file3,[...]]]: files to be excluded of backup\n"
|
|
|
|
+ printf "\t\tSeparate files with commas \",\"\n"
|
|
|
|
+ printf "\t\tDefault: %s\n" $exclude
|
|
printf "\n"
|
|
printf "\n"
|
|
printf "Compression Options:\n"
|
|
printf "Compression Options:\n"
|
|
printf "\t-z, --gzip: compress using gzip (tar.gz or tar.gz.gpg)\n"
|
|
printf "\t-z, --gzip: compress using gzip (tar.gz or tar.gz.gpg)\n"
|
|
@@ -172,20 +175,20 @@ function usage {
|
|
printf "\t\tDisable SQL backup\n"
|
|
printf "\t\tDisable SQL backup\n"
|
|
printf "\t·%s -j -k ABCDEFG --sql-user root --sql-password toor /var/www/backup\n" $(basename $0)
|
|
printf "\t·%s -j -k ABCDEFG --sql-user root --sql-password toor /var/www/backup\n" $(basename $0)
|
|
printf "\t\tMake a backup in \"/var/www/backup\" compressed with BZip2 and encrypted\n"
|
|
printf "\t\tMake a backup in \"/var/www/backup\" compressed with BZip2 and encrypted\n"
|
|
- printf "\t\t(\"backup-'hostname'-2018-03-19-abcdef.tar.bz2.gpg\")\n"
|
|
|
|
|
|
+ printf "\t\t(\"backup-%s-2018-03-19-abcdef.tar.bz2.gpg\")\n" $(hostname)
|
|
printf "\t·%s -z --no-encryption --no-sql /var/backup\n" $(basename $0)
|
|
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\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"
|
|
|
|
|
|
+ printf "\t\t(\"backup-%s-2018-03-19-qwerty.tar.gz\")\n" $(hostname)
|
|
}
|
|
}
|
|
|
|
|
|
function makeTar {
|
|
function makeTar {
|
|
#Destination file
|
|
#Destination file
|
|
- printf "Backup File:\t%s\n" $backupOutput
|
|
|
|
|
|
+ printf "Backup File:\t%s\n" $(realpath $backupOutput)
|
|
|
|
|
|
#Copy webpages code (except backup and main/public)
|
|
#Copy webpages code (except backup and main/public)
|
|
if [ $noWeb = false ];then
|
|
if [ $noWeb = false ];then
|
|
printf "Adding:\t%s\n" $webDir
|
|
printf "Adding:\t%s\n" $webDir
|
|
- tar -rf $tempOutput --exclude=var/www/backup --exclude=var/www/main/public $webDir > /dev/null 2>&1
|
|
|
|
|
|
+ tar -rf $tempOutput $exclude $webDir > /dev/null 2>&1
|
|
if [ $? != 0 ]; then
|
|
if [ $? != 0 ]; then
|
|
printf "WARNING:\tError copying web pages (Continue).\n"
|
|
printf "WARNING:\tError copying web pages (Continue).\n"
|
|
fi
|
|
fi
|
|
@@ -224,7 +227,7 @@ function makeTar {
|
|
#Copy nginx configuration (sites-available)
|
|
#Copy nginx configuration (sites-available)
|
|
if [ $noNginx = false ];then
|
|
if [ $noNginx = false ];then
|
|
printf "Adding:\t%s\n" $nginxDir
|
|
printf "Adding:\t%s\n" $nginxDir
|
|
- tar -rf $tempOutput $nginxDir > /dev/null 2>&1
|
|
|
|
|
|
+ tar -rf $tempOutput $exclude $nginxDir > /dev/null 2>&1
|
|
if [ $? != 0 ];then
|
|
if [ $? != 0 ];then
|
|
printf "WARNING:\tError copying nginx configuration (Continue)\n"
|
|
printf "WARNING:\tError copying nginx configuration (Continue)\n"
|
|
fi
|
|
fi
|
|
@@ -233,7 +236,7 @@ function makeTar {
|
|
#Copy Email (this could be heavy in the future)
|
|
#Copy Email (this could be heavy in the future)
|
|
if [ $noMail = false ];then
|
|
if [ $noMail = false ];then
|
|
printf "Adding:\t%s\n" $mailDir
|
|
printf "Adding:\t%s\n" $mailDir
|
|
- tar -rf $tempOutput $mailDir > /dev/null 2>&1
|
|
|
|
|
|
+ tar -rf $tempOutput $exclude $mailDir > /dev/null 2>&1
|
|
if [ $? != 0 ];then
|
|
if [ $? != 0 ];then
|
|
printf "WARNING:\tError copying mailboxes (Continue)\n"
|
|
printf "WARNING:\tError copying mailboxes (Continue)\n"
|
|
fi
|
|
fi
|
|
@@ -242,7 +245,7 @@ function makeTar {
|
|
#Copy Certificates (LetsEncrypt)
|
|
#Copy Certificates (LetsEncrypt)
|
|
if [ $noLetsencrypt = false ];then
|
|
if [ $noLetsencrypt = false ];then
|
|
printf "Adding:\t%s\n" $letsencryptDir
|
|
printf "Adding:\t%s\n" $letsencryptDir
|
|
- tar -rf $tempOutput $letsencryptDir > /dev/null 2>&1
|
|
|
|
|
|
+ tar -rf $tempOutput $exclude $letsencryptDir > /dev/null 2>&1
|
|
if [ $? != 0 ];then
|
|
if [ $? != 0 ];then
|
|
printf "WARNING:\tError copying Let's Encrypt certificates (Continue)\n"
|
|
printf "WARNING:\tError copying Let's Encrypt certificates (Continue)\n"
|
|
fi
|
|
fi
|
|
@@ -251,7 +254,7 @@ function makeTar {
|
|
#Copy /home
|
|
#Copy /home
|
|
if [ $noHome = false ];then
|
|
if [ $noHome = false ];then
|
|
printf "Adding:\t%s\n" $homeDir
|
|
printf "Adding:\t%s\n" $homeDir
|
|
- tar -rf $tempOutput $homeDir > /dev/null 2>&1
|
|
|
|
|
|
+ tar -rf $tempOutput $exclude $homeDir > /dev/null 2>&1
|
|
if [ $? != 0 ];then
|
|
if [ $? != 0 ];then
|
|
printf "WARNING:\tError copying home dir (Continue)\n"
|
|
printf "WARNING:\tError copying home dir (Continue)\n"
|
|
fi
|
|
fi
|
|
@@ -260,7 +263,7 @@ function makeTar {
|
|
#Copy GOGS
|
|
#Copy GOGS
|
|
if [ $noGogs = false ];then
|
|
if [ $noGogs = false ];then
|
|
printf "Adding:\t%s\n" $gogsDir
|
|
printf "Adding:\t%s\n" $gogsDir
|
|
- tar -rf $tempOutput $gogsDir > /dev/null 2>&1
|
|
|
|
|
|
+ tar -rf $tempOutput $exclude $gogsDir > /dev/null 2>&1
|
|
if [ $? != 0 ];then
|
|
if [ $? != 0 ];then
|
|
printf "WARNING:\tError copying GOGS Repository (Continue)\n"
|
|
printf "WARNING:\tError copying GOGS Repository (Continue)\n"
|
|
fi
|
|
fi
|
|
@@ -269,7 +272,7 @@ function makeTar {
|
|
#Copy Postfix
|
|
#Copy Postfix
|
|
if [ $noPostfix = false ] && [ -d $postfixDir ];then
|
|
if [ $noPostfix = false ] && [ -d $postfixDir ];then
|
|
printf "Adding:\t%s\n" $postfixDir
|
|
printf "Adding:\t%s\n" $postfixDir
|
|
- tar -rf $tempOutput $postfixDir > /dev/null 2>&1
|
|
|
|
|
|
+ tar -rf $tempOutput $exclude $postfixDir > /dev/null 2>&1
|
|
if [ $? != 0 ];then
|
|
if [ $? != 0 ];then
|
|
printf "WARNING:\tError copying Postfix configuration (Continue)\n"
|
|
printf "WARNING:\tError copying Postfix configuration (Continue)\n"
|
|
fi
|
|
fi
|
|
@@ -278,7 +281,7 @@ function makeTar {
|
|
#Copy Dovecot
|
|
#Copy Dovecot
|
|
if [ $noDovecot = false ];then
|
|
if [ $noDovecot = false ];then
|
|
printf "Adding:\t%s\n" $dovecotDir
|
|
printf "Adding:\t%s\n" $dovecotDir
|
|
- tar -rf $tempOutput $dovecotDir > /dev/null 2>&1
|
|
|
|
|
|
+ tar -rf $tempOutput $exclude $dovecotDir > /dev/null 2>&1
|
|
if [ $? != 0 ];then
|
|
if [ $? != 0 ];then
|
|
printf "WARNING:\tError copying Dovecot configuration (Continue)\n"
|
|
printf "WARNING:\tError copying Dovecot configuration (Continue)\n"
|
|
fi
|
|
fi
|
|
@@ -288,39 +291,33 @@ function makeTar {
|
|
if [ $noOpenDKIM = false ];then
|
|
if [ $noOpenDKIM = false ];then
|
|
if [ -f $openDKIMConf ];then
|
|
if [ -f $openDKIMConf ];then
|
|
printf "Adding:\t%s\n" $openDKIMConf
|
|
printf "Adding:\t%s\n" $openDKIMConf
|
|
- tar -rf $tempOutput $openDKIMConf > /dev/null 2>&1
|
|
|
|
|
|
+ tar -rf $tempOutput $exclude $openDKIMConf > /dev/null 2>&1
|
|
if [ $? != 0 ];then
|
|
if [ $? != 0 ];then
|
|
printf "WARNING:\tError copying OpenDKIM configuration (Continue)\n"
|
|
printf "WARNING:\tError copying OpenDKIM configuration (Continue)\n"
|
|
fi
|
|
fi
|
|
- else
|
|
|
|
- printf "WARNING:\tFile %s not exist\n" $openDKIMConf
|
|
|
|
fi
|
|
fi
|
|
if [ -f $openDKIMDefault ];then
|
|
if [ -f $openDKIMDefault ];then
|
|
printf "Adding:\t%s\n" $openDKIMDefault
|
|
printf "Adding:\t%s\n" $openDKIMDefault
|
|
- tar -rf $tempOutput $openDKIMDefault > /dev/null 2>&1
|
|
|
|
|
|
+ tar -rf $tempOutput $exclude $openDKIMDefault > /dev/null 2>&1
|
|
if [ $? != 0 ];then
|
|
if [ $? != 0 ];then
|
|
printf "WARNING:\tError copying OpenDKIM sockets configuration (Continue)\n"
|
|
printf "WARNING:\tError copying OpenDKIM sockets configuration (Continue)\n"
|
|
fi
|
|
fi
|
|
- else
|
|
|
|
- printf "WARNING:\tFile %s not exist\n" $openDKIMDefault
|
|
|
|
fi
|
|
fi
|
|
if [ -d $openDKIMKeys ];then
|
|
if [ -d $openDKIMKeys ];then
|
|
printf "Adding:\t%s\n" $openDKIMKeys
|
|
printf "Adding:\t%s\n" $openDKIMKeys
|
|
- tar -rf $tempOutput $openDKIMKeys > /dev/null 2>&1
|
|
|
|
|
|
+ tar -rf $tempOutput $exclude $openDKIMKeys > /dev/null 2>&1
|
|
if [ $? != 0 ];then
|
|
if [ $? != 0 ];then
|
|
printf "WARNING:\tError copying OpenDKIM keys (Continue)\n"
|
|
printf "WARNING:\tError copying OpenDKIM keys (Continue)\n"
|
|
fi
|
|
fi
|
|
- else
|
|
|
|
- printf "WARNING:\tDir %s not exist\n" $openDKIMKeys
|
|
|
|
fi
|
|
fi
|
|
fi
|
|
fi
|
|
|
|
|
|
#Copy SPF
|
|
#Copy SPF
|
|
if [ $noSPF = false ];then
|
|
if [ $noSPF = false ];then
|
|
printf "Adding:\t%s\n" $spfDir
|
|
printf "Adding:\t%s\n" $spfDir
|
|
- tar -rf $tempOutput $spfDir > /dev/null 2>&1
|
|
|
|
|
|
+ tar -rf $tempOutput $exclude $spfDir > /dev/null 2>&1
|
|
if [ $? != 0 ];then
|
|
if [ $? != 0 ];then
|
|
- printf "WARNING:\tError copying Postfix configuration (Continue)\n"
|
|
|
|
|
|
+ printf "WARNING:\tError copying SPF configuration (Continue)\n"
|
|
fi
|
|
fi
|
|
fi
|
|
fi
|
|
|
|
|
|
@@ -328,28 +325,24 @@ function makeTar {
|
|
if [ $noOpenDMARC = false ];then
|
|
if [ $noOpenDMARC = false ];then
|
|
if [ -f $openDMARCConf ];then
|
|
if [ -f $openDMARCConf ];then
|
|
printf "Adding:\t%s\n" $openDMARCConf
|
|
printf "Adding:\t%s\n" $openDMARCConf
|
|
- tar -rf $tempOutput $openDMARCConf > /dev/null 2>&1
|
|
|
|
|
|
+ tar -rf $tempOutput $exclude $openDMARCConf > /dev/null 2>&1
|
|
if [ $? != 0 ];then
|
|
if [ $? != 0 ];then
|
|
printf "WARNING:\tError copying OpenDMARC configuration (Continue)\n"
|
|
printf "WARNING:\tError copying OpenDMARC configuration (Continue)\n"
|
|
fi
|
|
fi
|
|
- else
|
|
|
|
- printf "WARNING:\tFile %s not exist\n" $openDMARCConf
|
|
|
|
fi
|
|
fi
|
|
if [ -f $openDMARCDefault ];then
|
|
if [ -f $openDMARCDefault ];then
|
|
printf "Adding:\t%s\n" $openDMARCDefault
|
|
printf "Adding:\t%s\n" $openDMARCDefault
|
|
- tar -rf $tempOutput $openDMARCDefault > /dev/null 2>&1
|
|
|
|
|
|
+ tar -rf $tempOutput $exclude $openDMARCDefault > /dev/null 2>&1
|
|
if [ $? != 0 ];then
|
|
if [ $? != 0 ];then
|
|
printf "WARNING:\tError copying OpenDMARC sockets configuration (Continue)\n"
|
|
printf "WARNING:\tError copying OpenDMARC sockets configuration (Continue)\n"
|
|
fi
|
|
fi
|
|
- else
|
|
|
|
- printf "WARNING:\tFile %s not exist\n" $openDMARCDefault
|
|
|
|
fi
|
|
fi
|
|
fi
|
|
fi
|
|
|
|
|
|
#Copy Amavis
|
|
#Copy Amavis
|
|
if [ $noAmavis = false ];then
|
|
if [ $noAmavis = false ];then
|
|
printf "Adding:\t%s\n" $amavisDir
|
|
printf "Adding:\t%s\n" $amavisDir
|
|
- tar -rf $tempOutput $amavisDir > /dev/null 2>&1
|
|
|
|
|
|
+ tar -rf $tempOutput $exclude $amavisDir > /dev/null 2>&1
|
|
if [ $? != 0 ];then
|
|
if [ $? != 0 ];then
|
|
printf "WARNING:\tError copying Amavis configuration (Continue)\n"
|
|
printf "WARNING:\tError copying Amavis configuration (Continue)\n"
|
|
fi
|
|
fi
|
|
@@ -358,7 +351,7 @@ function makeTar {
|
|
#Copy SPAMAssassin
|
|
#Copy SPAMAssassin
|
|
if [ $noSpamAssassin = false ];then
|
|
if [ $noSpamAssassin = false ];then
|
|
printf "Adding:\t%s\n" $spamAssassinDir
|
|
printf "Adding:\t%s\n" $spamAssassinDir
|
|
- tar -rf $tempOutput $spamAssassinDir > /dev/null 2>&1
|
|
|
|
|
|
+ tar -rf $tempOutput $exclude $spamAssassinDir > /dev/null 2>&1
|
|
if [ $? != 0 ];then
|
|
if [ $? != 0 ];then
|
|
printf "WARNING:\tError copying SPAM Assasin configuration (Continue)\n"
|
|
printf "WARNING:\tError copying SPAM Assasin configuration (Continue)\n"
|
|
fi
|
|
fi
|
|
@@ -498,7 +491,7 @@ function checkRoutes {
|
|
fi
|
|
fi
|
|
if [ $noSPF = false ] && [ ! -d $spfDir ];then
|
|
if [ $noSPF = false ] && [ ! -d $spfDir ];then
|
|
printf "WARNING:\t%s don't exist (no backup)\n" $spfDir
|
|
printf "WARNING:\t%s don't exist (no backup)\n" $spfDir
|
|
- noSpf=true
|
|
|
|
|
|
+ noSPF=true
|
|
fi
|
|
fi
|
|
# No noOpenDMARC=true, to make a parcial copy
|
|
# No noOpenDMARC=true, to make a parcial copy
|
|
if [ $noOpenDMARC = false ] && [ ! -f $openDMARCConf ];then
|
|
if [ $noOpenDMARC = false ] && [ ! -f $openDMARCConf ];then
|
|
@@ -574,6 +567,7 @@ backupPostfix=-$(date +"%Y-%m-%d")-$(cat /dev/urandom | tr -dc 'a-z0-9' | fold -
|
|
deleteDays="15"
|
|
deleteDays="15"
|
|
user="www-data"
|
|
user="www-data"
|
|
group="www-data"
|
|
group="www-data"
|
|
|
|
+exclude=""
|
|
|
|
|
|
#Default Routes
|
|
#Default Routes
|
|
webDir="/var/www"
|
|
webDir="/var/www"
|
|
@@ -618,7 +612,7 @@ noSpamAssassin=false
|
|
sha512=true
|
|
sha512=true
|
|
|
|
|
|
#Parse args
|
|
#Parse args
|
|
-TEMP=$(getopt -q -o zjJp:u:g:k:h --longoptions gzip,bzip2,xz,prefix:,postfix:,no-remove,remove-days:,user:,group:,permision-mask:,key-id:,no-encryption,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) -- $@)
|
|
|
|
|
|
+TEMP=$(getopt -q -o zjJp:u:g:e:k:h --longoptions gzip,bzip2,xz,prefix:,postfix:,no-remove,remove-days:,user:,group:,permision-mask:,exclude:,key-id:,no-encryption,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
|
|
eval set -- $TEMP
|
|
unset TEMP
|
|
unset TEMP
|
|
while true; do
|
|
while true; do
|
|
@@ -707,6 +701,24 @@ while true; do
|
|
fi
|
|
fi
|
|
shift 2
|
|
shift 2
|
|
;;
|
|
;;
|
|
|
|
+ -e|--exclude)
|
|
|
|
+ cont=1
|
|
|
|
+ fileCut=$(echo $2 | cut -d "," -f $cont)
|
|
|
|
+ fileCut=$(realpath -q -m $fileCut 2>/dev/null)
|
|
|
|
+ while [ $fileCut != "" ] > /dev/null 2>&1
|
|
|
|
+ do
|
|
|
|
+ if [ -d $fileCut ] || [ -f $fileCut ];then
|
|
|
|
+ exclude="$exclude --exclude=$fileCut"
|
|
|
|
+ else
|
|
|
|
+ printf "WARNING:\t%s don't exist\n" $fileCut
|
|
|
|
+ fi
|
|
|
|
+ cont=$((cont+1))
|
|
|
|
+ fileCut=$(echo $2 | cut -d "," -f $cont)
|
|
|
|
+ fileCut=$(realpath -q -m $fileCut 2>/dev/null)
|
|
|
|
+ done
|
|
|
|
+ unset cont fileCut
|
|
|
|
+ shift 2
|
|
|
|
+ ;;
|
|
-k|--key-id)
|
|
-k|--key-id)
|
|
keyID=$2
|
|
keyID=$2
|
|
shift 2
|
|
shift 2
|