![]() # (0-59) (0-23) (1-31) (1-12 or Jan-Dec) (0-6 or Sun-Sat)ģ0 4 * * 1-6 /home/users/backup.sh > /dev/null 2>&1Īnd that's it. If you run multiple WordPress websites on your web server like I do, you will need to make regular backups. (BTW, you can optionally add a mysql command before the dump, as noted on the previous answer if you need it)ģ) We do a chmod +x /home/users/backup.sh so it can be executable.ģ.1) You should test your script if it works as intendedĤ) We program the task with crontab -e # Minute Hour Day of Month Month Day of Week Command sql files in the directory, then it will delete all the. Use the crontab to make the process of backup automatic. This script will find the files with more than 7 days and delete them, then it will make the sql dump, then it will 7-zip all the. Use the mysqldump command for creating the backup SQL file, gzip to compress it, and run the script. Mysqldump -uroot -p MyDatabase >/home/users/backup_MyDB/$(date +%F)_full_myDB.sqlħz a /home/users/backup_MyDB/$(date +%F)_full_myDB.7z /home/users/backup_MyDB/*.sql The command above will create a dump file containing both databases. mysqldump -u root -p -databases databasenamea databasenameb > databasesab.sql. To mention the password of the database user that you chose to provide in the previous variable. To let you set the database username that has access to take a dump of the previous mentioned database. This is used in the MySQL script for taking database dump/backup. After that, enter your email in the Cron email section if you want to. ![]() Then, head to the Advanced tab and select Cron Jobs. Let’s take a quick look at the steps to do this: First, log in to cPanel. ![]() Hence, taking a backup at regular intervals is extremely important. Anyone know of a good way to accomplish this Thanks in advance. To specify which database is to be backed up. The database is responsible for storing the website’s critical information. ![]() I assume I can do this using a bash script. Each database name must be separated by space. I want to setup a cron job to run so that it will automatically backup my MySQL database, while the database is running, and then FTP that backup to my backup server. If your linux distro supports it, you can use the apt installer: sudo apt-get install p7zip-fullĪlternatively, you can use tar.gz if you feel more comfortable with it.Ģ) Then, you create a script, for example /home/users/backup.shįind /home/users/backup_MyDB -type f -mtime +7 -exec rm + To backup multiple MySQL databases with one command you need to use the -database option followed by the list of databases you want to backup. Hopefully somebody else finds this useful.ġ) Researching a bit, 7-zip seems the best compressor out there. DATABASEdbname DBUSERdbuser DBPASSWDdbpassword PATH/home4/username/my-backups/site-name/. If you want to set it up locally then you could use something like task scheduler of the corresponding operating system to call the php script followed by the url as the argument. I know it's a big old, but I've used the above answers, and added a file compression instruction. Backup MySQL database using cron and php. If you have it on a live server, you could setup a cron jobs to call the php file. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |