MySQL – Backup and Restore

Last updated on August 13th, 2019 at 09:41 am

BackUP Script

mkdir /backup/www+mysql
mysqldump --user=backup --password=123456 dbtest > /backup/www+mysql/wiki.sql

tar -cvzf /backup/www+mysql/httpd.tar.gz /etc/httpd/conf/httpd.conf
tar -cvzf /backup/www+mysql/www.tar.gz /var/www

tar -cvzf /backup/www+mysql$(date +%d-%m-%Y).tar.gz /bckp/www+mysql

ls /bckp > /backup/www+mysql/backup.txt

find /backup/*.* -mtime +7 -exec rm {} \;

echo ' BackUp Done' | mail -r [email protected] -s ' BackUp Done' [email protected] < /backup/www+mysql/backup.txt
rm -rf /backup/www+mysql

Change your parameters in this script and save it and add this to cron job

Restore MySQL

 mysql -uYour_User -p'Your_Password' Your_DB < Your_Backup.sql