Backup script for files and database
Hello guys.
This is a simple script to take a backup of files and database and copy the data to a storage server/VPS. You can use it on you VPS if it’s a no Panel server.
Backup script for files and database.
vimĀ /root/backup-daily.sh
Save the following script and set the cronjob as you wish. If you don’t wish to copy the data to remote storage then remove last two rsync command from the script.
#!/bin/bash path1="/backup/dbbackups" rm -f /backup/dbbackups.tar.gz rm -f /tmp/dblist.txt # List all databases in server mysql -e 'show databases;'| awk '{ print $1 }' | egrep -v "Database|information_schema|performance_schema" > /tmp/dblist.txt mkdir -p $path1 #Create database dump of all database listed above to /home/dbbackups for i in `cat /tmp/dblist.txt` ; do sleep 2; echo "Creating dbbackup of $i" ; /usr/bin/mysqldump $i > $path1/$i.sql ; done echo Successfully created backup of all databases to $path1 cd /backup tar -zcvf /backup/dbbackups.tar.gz dbbackups rsync -avu --exclude=.ssh --delete /backup/ [email protected]:/mnt/backup/daily/db_backup/root_password rsync -avu --exclude=.ssh --delete /home/ [email protected]:/mnt/backup/daily/home_backup/root_password
That’s all…if you have any doubt’s please comment.