Added encrypted backup function

This commit is contained in:
2020-09-17 14:00:11 +02:00
parent f44cfb0217
commit 0400e31178
3 changed files with 51 additions and 8 deletions

View File

@@ -2,6 +2,7 @@
RMDAYS=14 #Days until first backup gets removed RMDAYS=14 #Days until first backup gets removed
DOMC=01 #Day of month for monthly backups DOMC=01 #Day of month for monthly backups
SYSTEMFILES="/etc/nginx/ /etc/apache2/ /etc/php/ /etc/mysql/ /etc/crontab /opt/" #Folders and files that will be backed SYSTEMFILES="/etc/nginx/ /etc/apache2/ /etc/php/ /etc/mysql/ /etc/crontab /opt/" #Folders and files that will be backed
SYSBACKENC=0 #Sets if system files use encrypyed tar archive
#Remote #Remote
BACKUPSERVICE=sftp #Transfer prtocal use ftp or sftp BACKUPSERVICE=sftp #Transfer prtocal use ftp or sftp
@@ -15,6 +16,10 @@ REMOTEPATH=/home #Path were backup wil be stored on FTP
DBUSER='root' #MySQL Username DBUSER='root' #MySQL Username
DBPASS='<MSQLRootPW>' #MySQL Root password (syntax '<MSQLRootPW>') DBPASS='<MSQLRootPW>' #MySQL Root password (syntax '<MSQLRootPW>')
#RSYNC
RSPORT=22 #Rsync port
##SiteBackup site backup command, multiple commands are allowed ##SiteBackup site backup command, multiple commands are allowed
#example: SiteBackup -d domain.com -sn domain -db wp_093 -sd "/var/www/domain.com/html" -ext-files "/ext/test.txt" -ai1 -wpupdate #example: SiteBackup -d domain.com -sn domain -db wp_093 -sd "/var/www/domain.com/html" -ext-files "/ext/test.txt" -ai1 -wpupdate
# #
@@ -26,6 +31,8 @@ DBPASS='<MSQLRootPW>' #MySQL Root password (syntax '<MSQLRoot
# -ai1 #Enable WP all in one migration backup # -ai1 #Enable WP all in one migration backup
# -wpupdate #Enable WP updatedb # -wpupdate #Enable WP updatedb
# -nodb #Disable databse backup # -nodb #Disable databse backup
# -snotar #Disable site Tar backup # -snotar #Disable site tar creation
# -srsync #syncs site folder via rsync
# -srsyncdel #also syncs deletes monthly (day set by DOMC)
# -tarenc #Enables encrypyed site Tar backup

View File

@@ -11,8 +11,9 @@ function SiteBackup () {
WPUPDATE=0 WPUPDATE=0
AI1=0 AI1=0
SITEBACKENC=0
TEMP=`getopt -a -o d: -l sn:,db:,sd:,ext-files:,ai1,wpupdate,nodb,snotar,srsync,srsyncdel -- "$@"` TEMP=`getopt -a -o d: -l sn:,db:,sd:,ext-files:,ai1,wpupdate,nodb,snotar,srsync,srsyncdel,tarenc -- "$@"`
eval set -- "$TEMP" eval set -- "$TEMP"
while true ; do while true ; do
case "$1" in case "$1" in
@@ -60,6 +61,10 @@ while true ; do
SRSYNCDEL=1 SRSYNCDEL=1
shift 1 shift 1
;; ;;
--tarenc )
SITEBACKENC=1
shift 1
;;
--ext-files ) --ext-files )
SITEEF=$2 SITEEF=$2
shift 2 shift 2
@@ -74,6 +79,11 @@ DBARRY=($DBNAME)
echo "Making backup of $SITENAME" echo "Making backup of $SITENAME"
if [ ! -f "$ScriptLocation/key.bin" ] && [ $SITEBACKENC -eq 1 ] ; then
echo "Encription key not found"
exit
fi
##SITE Run ##SITE Run
#creating folder #creating folder
SITESENDDIR="$SENDDIR/$TODAY/$SITENAME/" SITESENDDIR="$SENDDIR/$TODAY/$SITENAME/"
@@ -84,7 +94,12 @@ if [ "$AI1" = "1" ]; then
sudo -u "$SITENAME" wp --path="$SITEDIR" plugin update all-in-one-wp-migration-unlimited-extension sudo -u "$SITENAME" wp --path="$SITEDIR" plugin update all-in-one-wp-migration-unlimited-extension
sudo -u "$SITENAME" wp --path="$SITEDIR" plugin update all-in-one-wp-migration sudo -u "$SITENAME" wp --path="$SITEDIR" plugin update all-in-one-wp-migration
sudo -u "$SITENAME" wp --path="$SITEDIR" ai1wm backup sudo -u "$SITENAME" wp --path="$SITEDIR" ai1wm backup
find "$SITEDIR"/wp-content/ai1wm-backups/ -name "*.wpress" -printf "%P\n"| tar -czf /"$SITESENDDIR"/"$SITENAME"-ai1wm.tar.gz --no-recursion -C "$SITEDIR"/wp-content/ai1wm-backups/ -T - #Create ai1wm tar File if [ $SITEBACKENC -eq 1 ] ; then
find "$SITEDIR"/wp-content/ai1wm-backups/ -name "*.wpress" -printf "%P\n"| tar -czf - --no-recursion -C "$SITEDIR"/wp-content/ai1wm-backups/ -T - | openssl enc -e -aes256 -pass file:"$ScriptLocation"/key.bin -out /"$SITESENDDIR"/"$SITENAME"-ai1wm.tar.gz #Create ai1wm tar File
cp "$ScriptLocation"/key.bin.enc /"$SITESENDDIR"/"$SITENAME"-ai1wm.key.enc
else
find "$SITEDIR"/wp-content/ai1wm-backups/ -name "*.wpress" -printf "%P\n"| tar -czf /"$SITESENDDIR"/"$SITENAME"-ai1wm.tar.gz --no-recursion -C "$SITEDIR"/wp-content/ai1wm-backups/ -T - #Create ai1wm tar File
fi
rm -f "$SITEDIR"/wp-content/ai1wm-backups/*.wpress rm -f "$SITEDIR"/wp-content/ai1wm-backups/*.wpress
fi fi
@@ -94,13 +109,23 @@ if [ "$NODB" != "1" ]; then
do do
mysqldump -u "$DBUSER" "$i" --password="$DBPASS" --default-character-set=utf8 > "$TMPDIR"/"$SITENAME"-"$i".sql mysqldump -u "$DBUSER" "$i" --password="$DBPASS" --default-character-set=utf8 > "$TMPDIR"/"$SITENAME"-"$i".sql
done done
find "$TMPDIR" -name "*.sql" -printf "%P\n"| tar -czf /"$SITESENDDIR"/"$SITENAME"-DB.tar.gz --no-recursion -C "$TMPDIR" -T - #Create tar File if [ $SITEBACKENC -eq 1 ] ; then
find "$TMPDIR" -name "*.sql" -printf "%P\n"| tar -czf - --no-recursion -C "$TMPDIR" -T - | openssl enc -e -aes256 -pass file:"$ScriptLocation"/key.bin -out /"$SITESENDDIR"/"$SITENAME"-DB.tar.gz #Create tar File
cp "$ScriptLocation"/key.bin.enc /"$SITESENDDIR"/"$SITENAME"-DB.key.enc
else
find "$TMPDIR" -name "*.sql" -printf "%P\n"| tar -czf /"$SITESENDDIR"/"$SITENAME"-DB.tar.gz --no-recursion -C "$TMPDIR" -T - #Create tar File
fi
rm -f /"$TMPDIR"/*.sql rm -f /"$TMPDIR"/*.sql
fi fi
#Taronmogelijking SiteFiles files #Taronmogelijking SiteFiles files
if [ "$SNOTAR" != "1" ]; then if [ "$SNOTAR" != "1" ]; then
tar -zcf /"$SITESENDDIR"/"$SITENAME"-Files.tar.gz $SITEDIR $SITEEF if [ $SITEBACKENC -eq 1 ] ; then
tar -zcf - $SITEDIR $SITEEF | openssl enc -e -aes256 -pass file:"$ScriptLocation"/key.bin -out /"$SITESENDDIR"/"$SITENAME"-Files.tar.gz #Create tar File
cp "$ScriptLocation"/key.bin.enc /"$SITESENDDIR"/"$SITENAME"-Files.key.enc
else
tar -zcf /"$SITESENDDIR"/"$SITENAME"-Files.tar.gz $SITEDIR $SITEEF
fi
fi fi
#Running WP Update #Running WP Update
@@ -135,10 +160,20 @@ source "$ScriptLocation/Backup-Util.conf"
echo "Making backup of System" echo "Making backup of System"
#SYSTEM run #SYSTEM run
if [ ! -f "$ScriptLocation/key.bin" ] && [ $SYSBACKENC -eq 1 ] ; then
echo "Encription key not found"
exit
fi
#Taring SiteFiles files #Taring SiteFiles files
SYSSENDDIR="$SENDDIR/$TODAY/System/" SYSSENDDIR="$SENDDIR/$TODAY/System/"
mkdir -p $SYSSENDDIR mkdir -p $SYSSENDDIR
tar -zcf /"$SYSSENDDIR"/$(hostname -s)-Files.tar.gz $SYSTEMFILES if [ $SYSBACKENC -eq 1 ] ; then
tar -zcf - $SYSTEMFILES | openssl enc -e -aes256 -pass file:"$ScriptLocation"/key.bin -out /"$SYSSENDDIR"/$(hostname -s)-Files.tar.gz
cp "$ScriptLocation"/key.bin.enc /"$SYSSENDDIR"/$(hostname -s)-Files.key.enc
else
tar -zcf /"$SYSSENDDIR"/$(hostname -s)-Files.tar.gz $SYSTEMFILES
fi
echo "Sending files to remote server" echo "Sending files to remote server"

View File

@@ -2,6 +2,7 @@
RMDAYS=14 #Days until first backup gets removed RMDAYS=14 #Days until first backup gets removed
DOMC=01 #Day of month for monthly backups DOMC=01 #Day of month for monthly backups
SYSTEMFILES="/etc/nginx/ /etc/apache2/ /etc/php/ /etc/mysql/ /etc/crontab /opt/" #Folders and files that will be backed SYSTEMFILES="/etc/nginx/ /etc/apache2/ /etc/php/ /etc/mysql/ /etc/crontab /opt/" #Folders and files that will be backed
SYSBACKENC=0 #Sets if system files use encrypyed tar archive
#Remote #Remote
BACKUPSERVICE=sftp #Transfer prtocal use ftp or sftp BACKUPSERVICE=sftp #Transfer prtocal use ftp or sftp
@@ -33,6 +34,6 @@ RSPORT=22 #Rsync port
# -snotar #Disable site tar creation # -snotar #Disable site tar creation
# -srsync #syncs site folder via rsync # -srsync #syncs site folder via rsync
# -srsyncdel #also syncs deletes monthly (day set by DOMC) # -srsyncdel #also syncs deletes monthly (day set by DOMC)
# -tarenc #Enables encrypyed site Tar backup