From bc2279fe54652bfd55370ca4fbe7e038b130bb00 Mon Sep 17 00:00:00 2001 From: Bram Prieshof Date: Thu, 13 Feb 2020 10:36:12 +0100 Subject: [PATCH] Upload files to '' --- GiteaBackup.sh | 57 ++++++++++++++++ Nextcloud-Backup.sh | 75 +++++++++++++++++++++ WP_Ftp-Backup.sh | 137 ++++++++++++++++++++++++++++++++++++++ WP_Hourly_local-Backup.sh | 67 +++++++++++++++++++ install-backup-tools.sh | 49 ++++++++++++++ 5 files changed, 385 insertions(+) create mode 100644 GiteaBackup.sh create mode 100644 Nextcloud-Backup.sh create mode 100644 WP_Ftp-Backup.sh create mode 100644 WP_Hourly_local-Backup.sh create mode 100644 install-backup-tools.sh diff --git a/GiteaBackup.sh b/GiteaBackup.sh new file mode 100644 index 0000000..5976e87 --- /dev/null +++ b/GiteaBackup.sh @@ -0,0 +1,57 @@ +################################# +# +#Make sure lftp is installed +#if lftp has problem connecting try adding the folowing to /etc/lftp.conf +# set ssl:verify-certificate no +# set ftp:ssl-allow false +# +################################## +## Automation +## add to /etc/crontab and restart cron (/etc/init.d/cron restart) +#30 4 * * * root /bin/sh /root/GiteaBackup.sh +################################## + + + + + +##Configuration + +RMDAYS=14 #Days until first backup gets removed +FTPSERVER= #Addres of FTP Server +FTPUSER= #User for FTP Server +DBNAME= #Database that will be backed up +DBPASS= +BACKUPFROM="/etc/nginx/ /opt/ /etc/gitea/ /home/git/ /root/ /var/www /etc/lftp.conf /etc/crontab /home/nimda /usr/share/cockpit /etc/ssh /etc/pam.d/cockpit" #Folders and files that will be backed +SITENAME= #Name of site that will be backed up + +##Setting Static Variables +LFTP=/usr/bin/lftp # Path to binary +TMPDIR=$(mktemp -d) # Your archives are here +TODAY=$(date --iso) # Today's date like YYYY-MM-DD +RMDATE=$(date --iso -d "$RMDAYS days ago") # TODAY minus X days - too old files + + + + +##Run + + +cd $TMPDIR +#mysqldump -u root -p$ "$DBNAME" > "$TMPDIR"/"$SITENAME".sql #Dumping DB +mysqldump -u root "$DBNAME" --password="$DBPASS" --default-character-set=utf8 > "$TMPDIR"/"$SITENAME".sql #Dumping DB + +tar -zcf /"$TMPDIR"/"$SITENAME".tar.gz $BACKUPFROM #Create tar File + +#Uploading and remove first backup on FTP +$LFTP << EOF +open -u ${FTPUSER}, sftp://${FTPSERVER} +mkdir -p ${SITENAME}/${TODAY} +cd ${SITENAME}/${TODAY} +mput -E ${TMPDIR}/* +cd .. +rm -rf ${RMDATE} +bye +EOF + +rm -r "$TMPDIR" #Deletes Temp Folder diff --git a/Nextcloud-Backup.sh b/Nextcloud-Backup.sh new file mode 100644 index 0000000..6f16aa8 --- /dev/null +++ b/Nextcloud-Backup.sh @@ -0,0 +1,75 @@ +############################################################################### +# +# NEXTCLOUD BackupTool +# +# @author: Bram Prieshof +# +############################################################################### +## Automation +## +## Edit contab (nano /etc/crontab) +## Restart crontab (/etc/init.d/cron restart) +## +################################################################################# + + +##Configuration + +RMDAYS=14 #Days until first backup gets removed +DOMC=01 #Day of month for monthly removal of deleted files +REMOTESERVER= #Addres of Backup Server +REMOTEUSER= #User for Backup Server + +SYSNAME= #System Hostname +BACKUPFROM="/etc/nginx/ /etc/php/ /etc/mysql/ /etc/crontab /opt/ /etc/loolwsd/" #Folders and files that will be backed +DBPASS='' #MySQL Root password (syntax '') + + +DBNAME= #Database that will be backed up +ILOCATION="/var/www/" #Nextcloud instance Location +SITENAME= #Name of instance that will be backed up + + +####################################################################### +## ## +## PLEASE DO NOT MAKE CHANGES UNDER HERE ## +## ## +####################################################################### + + +##Setting Static Variables +LFTP=/usr/bin/lftp #Path to binary +TMPDIR=$(mktemp -d) #Your archives are here +SENDDIR=$(mktemp -d) #Sends everything in this folder to ftp +TODAY=$(date --iso) #Today's date like YYYY-MM-DD +RMDATE=$(date --iso -d "$RMDAYS days ago") #TODAY minus X days - too old files +DOM=`date '+%d'` #Day of the month + +##Run +#Rsyncing instance files +rsync -e 'ssh -p23' -a ${ILOCATION} "$REMOTEUSER"@"$REMOTESERVER":"$SITENAME" + +#Dumping DataBase +mysqldump -u root "$DBNAME" --password="$DBPASS" --default-character-set=utf8 > "$SENDDIR"/"$SITENAME".sql #Dumping DB + +#Taring Config files and DB +tar --exclude='/opt/collaboraoffice6.0' --exclude='/opt/lool' -zcf /"$SENDDIR"/"$SYSNAME"-Config-DB.tar.gz $BACKUPFROM #Create tar File + +#Uploading and remove first config-db backup on SFTP +$LFTP << EOF +open -u ${REMOTEUSER}, sftp://${REMOTESERVER} +mkdir -p ${SYSNAME}/${TODAY} +cd ${SYSNAME}/${TODAY} +mput -E ${SENDDIR}/* +cd .. +rm -rf ${RMDATE} +bye +EOF + +#Checking and running monthly backup to SFTP +if [ $DOM == $DOMC ]; then +rsync -e 'ssh -p23' --delete -a ${ILOCATION} "$REMOTEUSER"@"$REMOTESERVER":"$SITENAME" +fi + +#Deletes Temp Folder +rm -r "$TMPDIR" && rm -r "$SENDDIR" diff --git a/WP_Ftp-Backup.sh b/WP_Ftp-Backup.sh new file mode 100644 index 0000000..1ade18c --- /dev/null +++ b/WP_Ftp-Backup.sh @@ -0,0 +1,137 @@ +############################################################################### +# +#Make sure that install-backup-tools.sh has ran for this site configureation +# +# +############################################################################### +## Automation +## +## Edit contab (nano /etc/crontab) +## Restart crontab (/etc/init.d/cron restart) +## +################################################################################# +## SFTP +## if sftp is used comment line "FTPPW" and +## make sure ssh connection can be made with root's ssh key +## +################################################################################# + + +##Configuration + +RMDAYS=14 #Days until first backup gets removed +DOMC=01 #Day of month for monthly backups +BACKUPSERVICE=ftp #transfer prtocal use ftp or sftp +REMOTESERVER= #Addres of FTP Server +REMOTEUSER= #User for FTP Server +FTPPW= #Password for FTP Server ##Comment out if SFTP is used## +REMOTEPATH=/Rftp/backup/vps #Path were backup wil be stored on FTP and a site sub-folder will be made + +DOMAIN= #DomainName +SITENAME= #Name of site that will be backed up +BACKUPFROM="/etc/nginx/ /etc/apache2/ /etc/php/ /etc/mysql/ /etc/crontab /opt/ /var/www/"$DOMAIN"/" #Folders and files that will be backed + +DBNAME= #Database that will be backed up +DBPASS='' #MySQL Root password (syntax '') + +ENABLEUPDATE=1 #set to 1 to enable or to 0 to disable wordpress updates + + +############################################################################# +## # +## PLEASE DO NOT MAKE CHANGES UNDER HERE # +## # +############################################################################# + + +##Setting Static Variables +LFTP=/usr/bin/lftp #Path to binary +TMPDIR=$(mktemp -d) #Your archives are here +SENDDIR=$(mktemp -d) #Sends everything in this folder to ftp +TODAY=$(date --iso) #Today's date like YYYY-MM-DD +RMDATE=$(date --iso -d "$RMDAYS days ago") #TODAY minus X days - too old files +DOM=`date '+%d'` #Day of the month + + + +##Run + +#Creating AI1M file +sudo -u www-data wp --path=/var/www/"$DOMAIN"/html plugin update all-in-one-wp-migration-unlimited-extension +sudo -u www-data wp --path=/var/www/"$DOMAIN"/html plugin update all-in-one-wp-migration +cd /var/www/"$DOMAIN"/html +sudo -u www-data wp ai1wm backup +mv /var/www/"$DOMAIN"/html/wp-content/ai1wm-backups/*.wpress "$TMPDIR" +cd $TMPDIR +tar -zcf /"$SENDDIR"/"$SITENAME"-ai1wm.tar.gz -C $TMPDIR *.wpress #Create ai1wm tar File +rm -f /"$TMPDIR"/*.wpress + +#Dumping DataBase +mysqldump -u root "$DBNAME" --password="$DBPASS" --default-character-set=utf8 > "$TMPDIR"/"$SITENAME".sql #Dumping DB +tar -zcf /"$SENDDIR"/"$SITENAME"-DB.tar.gz -C "$TMPDIR" *.sql #Create tar File + +#Taring systemFiles files +tar -zcf /"$SENDDIR"/"$SITENAME"-Files.tar.gz $BACKUPFROM #Create tar File + +if [ $BACKUPSERVICE = ftp ]; then +#Uploading and remove first backup on FTP +$LFTP << EOF +open ${REMOTEUSER}:${FTPPW}@${REMOTESERVER} +cd "${REMOTEPATH}" +mkdir -p ${SITENAME}/${TODAY} +cd ${SITENAME}/${TODAY} +mput -E ${SENDDIR}/* +cd .. +rm -rf ${RMDATE} +bye +EOF + +#Checking and running monthly backup to FTP +if [ $DOM == $DOMC ]; then +$LFTP << EOF +open ${REMOTEUSER}:${FTPPW}@${REMOTESERVER} +cd "${REMOTEPATH}" +rm -rf ${SITENAME}/Monthly/ +mkdir -p ${SITENAME}/Monthly/ +cd ${SITENAME}/Monthly/ +mput -E ${SENDDIR}/* +bye +EOF +fi +elif [ $BACKUPSERVICE = sftp ]; then +#Uploading and remove first backup on SFTP +$LFTP << EOF +open -u ${REMOTEUSER}, sftp://${REMOTESERVER} +cd "${REMOTEPATH}" +mkdir -p ${SITENAME}/${TODAY} +cd ${SITENAME}/${TODAY} +mput -E ${SENDDIR}/* +cd .. +rm -rf ${RMDATE} +bye +EOF + +#Checking and running monthly backup to SFTP +if [ $DOM == $DOMC ]; then +$LFTP << EOF +open -u ${REMOTEUSER}, sftp://${REMOTESERVER} +cd "${REMOTEPATH}" +rm -rf ${SITENAME}/Monthly/ +mkdir -p ${SITENAME}/Monthly/ +cd ${SITENAME}/Monthly/ +mput -E ${SENDDIR}/* +bye +EOF +fi +fi + +#Deletes Temp Folder +rm -r "$TMPDIR" && rm -r "$SENDDIR" + +#Wordpress updates +if [ $ENABLEUPDATE = 1 ]; then +wp cli update +sudo -u www-data wp --path=/var/www/"$DOMAIN"/html core update +sudo -u www-data wp --path=/var/www/"$DOMAIN"/html plugin update --all +sudo -u www-data wp --path=/var/www/"$DOMAIN"/html theme update --all +fi diff --git a/WP_Hourly_local-Backup.sh b/WP_Hourly_local-Backup.sh new file mode 100644 index 0000000..cc2511a --- /dev/null +++ b/WP_Hourly_local-Backup.sh @@ -0,0 +1,67 @@ +############################################################################### +#Hourly wordpress backup script +# +#Make sure that install-backup-tools.sh has ran for this site configureation +# +# +############################################################################### +## Automation +## +## Edit contab (nano /etc/crontab) +## Restart crontab (/etc/init.d/cron restart) +## +################################################################################# + + +##Configuration + +DOMAIN= #DomainName +SITENAME= #Name of site that will be backed up +BACKUPFROM="/etc/nginx/ /etc/apache2/ /etc/php/ /etc/mysql/ /etc/crontab /var/www/"$DOMAIN"/" #Folders and files that will be backed +BACKUPTO="/backup" #Please enter path without tailing slash +DBNAME= #Database that will be backed up +DBPASS='' #MySQL Root password (syntax '') + +SYSBACKUP=1 #Enable or disable file backups +BDBACKUP=1 #Enable or disable database backups +AI1MBACKUP=1 #Enable or disable Ai1M backups + + +############################################################################# +## # +## PLEASE DO NOT MAKE CHANGES UNDER HERE # +## # +############################################################################# + + +##Setting Static Variables +LFTP=/usr/bin/lftp #Path to binary +TMPDIR=$(mktemp -d) #Your archives are here +BACKUPTO=${BACKUPTO}/$(date +"%H") #Sends everything in this folder to ftp + + +mkdir -p ${BACKUPTO} + +#AI1M backup +if [ $AI1MBACKUP = 1 ]; then +sudo -u www-data wp --path=/var/www/"$DOMAIN"/html plugin update all-in-one-wp-migration-unlimited-extension +sudo -u www-data wp --path=/var/www/"$DOMAIN"/html plugin update all-in-one-wp-migration +cd /var/www/"$DOMAIN"/html +sudo -u www-data wp ai1wm backup +mv /var/www/"$DOMAIN"/html/wp-content/ai1wm-backups/*.wpress "$TMPDIR" +cd $TMPDIR +tar -zcf /"$BACKUPTO"/"$SITENAME"-ai1wm.tar.gz -C $TMPDIR *.wpress #Create ai1wm tar File +rm -f /"$TMPDIR"/*.wpress +fi + +#Database Backup +if [ $BDBACKUP = 1 ]; then +mysqldump -u root "$DBNAME" --password="$DBPASS" > "$TMPDIR"/"$SITENAME".sql #Dumping DB +tar -zcf /"$BACKUPTO"/"$SITENAME"-DB.tar.gz -C "$TMPDIR" *.sql #Create tar File +fi + +if [ $SYSBACKUP = 1 ]; then +tar -zcf /"$BACKUPTO"/"$SITENAME"-Files.tar.gz $BACKUPFROM #Create tar File +fi + +rm -r "$TMPDIR" \ No newline at end of file diff --git a/install-backup-tools.sh b/install-backup-tools.sh new file mode 100644 index 0000000..757a564 --- /dev/null +++ b/install-backup-tools.sh @@ -0,0 +1,49 @@ +apt update + +echo "Domain without www:" +read domain + +while true; do + read -p "Is this the first run on this server? -> yes/no?" yn + case $yn in + [Yy]* ) fr=1 + break;; + [Nn]* ) fr=0 + break;; + * ) echo "Choose yes of no.";; + esac +done + +if [ $fr = 1 ]; then +############ +# lftp # +############ + +apt install -y lftp +sed -i -e '$a set ssl:verify-certificate no' /etc/lftp.conf +sed -i -e '$a set ftp:ssl-allow false' /etc/lftp.conf + +############## +# wp-cli # +############## +cd /opt +wget https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar -O /opt/wp-cli.phar +wget https://raw.githubusercontent.com/wp-cli/wp-cli/v1.5.1/utils/wp-completion.bash -O /opt/wp-completion.bash +chmod +x /opt/wp-cli.phar +mv /opt/wp-cli.phar /usr/local/bin/wp + +sed -i -e '$a source /opt/wp-completion.bash' ~/.bash_profile +source ~/.bash_profile +sed -i "\$a30 3 * * * root /bin/sh /opt/backup.sh >/dev/null 2>&1" /etc/crontab +systemctl restart cron +wget https://git.ictmaatwerk.com/VPS-scripts/Ubuntu-Backup/raw/branch/master/WP_Ftp-Backup.sh -O /opt/backup.sh +chmod +x /opt/backup.sh +fi + +wp cli update +sudo -u www-data wp --path=/var/www/"$domain"/html plugin install all-in-one-wp-migration --activate +sudo -u www-data wp --path=/var/www/"$domain"/html plugin install https://git.ictmaatwerk.com/downloads/wp/migrate.zip --activate +sudo -u www-data wp --path=/var/www/"$domain"/html plugin update --all +sudo -u www-data wp --path=/var/www/"$domain"/html core update + +echo "The backup script is placed in /opt/backup.sh" \ No newline at end of file