Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- echo Welcome to this backup script on $(date).
- sleep 1
- echo "Written by XXXX from XXXX (c) 2016"
- sleep 5
- ##################################
- # This is the first state of the program, here we will compress all individual webspace folders
- ##################################
- echo First we are going to create rar files for each domain.
- cd /
- cd var
- cd www
- cd vhosts
- echo We are now in the right directory, now rar will be executed... This will take a long time.
- sleep 5
- #for folder in */; do rar a -m0 -r "${folder%/}.rar" "$folder"; done
- for folder in */; do rar a -m0 -r "${folder%/}.rar" "$folder" > /dev/null 2>&1 ; echo Files for domain "${folder%/}" have been compressed. ; done ;
- echo Process complete. Moving files to temp space.
- mv *.rar /root/backup/files
- echo Moving completed.
- ##################################
- # This is the second state of the program where mail is backupped
- ##################################
- echo "We will now backup the mail using about the same method (using rar)."
- cd /
- cd var
- cd qmail
- cd mailnames
- echo We are now in the right directory, now rar will be executed... This will take a long time.
- sleep 5
- #for folder in */; do rar a -m0 -r "${folder%/}.rar" "$folder"; done
- for folder in */; do rar a -m0 -r "${folder%/}.mail.rar" "$folder" > /dev/null 2>&1 ; echo Mail for domain "${folder%/}" has been compressed. ; done ;
- echo Process complete. Moving files to temp space.
- mv *.rar /root/backup/mail
- echo All mail has been archived in the right directory. Proceeding to database backup..
- echo Changing working directory.
- ##################################
- # The third state, we are going to backup mysql
- ##################################
- cd /
- cd root
- cd backup
- cd sql
- echo Working directory changed.
- echo Commencing MySQL backup...
- # Optional variables for a backup script
- MYSQL_USER="admin"
- MYSQL_PASS=`cat /etc/psa/.psa.shadow`
- #BACKUP_DIR=/root/backup/sql/$(date +%F);
- BACKUP_DIR=/root/backup/sql/
- test -d "$BACKUP_DIR" || mkdir -p "$BACKUP_DIR"
- # Get the database list, exclude information_schema
- for db in $(mysql -B -s -u $MYSQL_USER --password=$MYSQL_PASS -e 'show databases' | grep -v information_schema)
- do
- # dump each database in a separate file
- echo Making backup of database "$db".
- mysqldump -u $MYSQL_USER --password=$MYSQL_PASS "$db" | gzip > "$BACKUP_DIR/$db.sql.gz"
- done
- echo Done backupping all databases.
- ##################################
- # The forth state, we are going to move the files, mail and sql folder to the upload dir
- ##################################
- echo Moving files to upload directory..
- BACKUP=/root/backup/upload/$(date +%F);
- mkdir $BACKUP
- echo Moving webspace rar files...
- mv /root/backup/files/* $BACKUP
- echo Done moving webspace rar files
- echo Moving mail rar files...
- mv /root/backup/mail/* $BACKUP
- echo Done moving mail rar files
- echo Moving database files...
- mv /root/backup/sql/* $BACKUP
- echo Done moving database files
- ##################################
- # The fifth state, uploading and copying
- ##################################
- echo Commencing FTP upload. This will take a long time
- ncftpput -R -v -u "XXXX" -p "XXXX" 83.162.184.234 /home/trustinternet.nl/Backup $BACKUP
- echo Upload complete.
- echo tranferring files to Strato cloud backup area $BACKUP please wait
- cp -R -v /root/backup/upload/* /private-backup
- echo Local copy completed.
- echo All done, cleaning up.
- ##################################
- # The sixth state, we remove the files we created, because the files are now safe off premises.
- ##################################
- rm -rf /root/backup/upload/*
- echo Backup finished on $(date).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement