{"id":4489,"date":"2016-01-26T03:16:02","date_gmt":"2016-01-26T03:16:02","guid":{"rendered":"http:\/\/www.www.smekdigital.com\/?p=4489"},"modified":"2016-01-26T03:16:02","modified_gmt":"2016-01-26T03:16:02","slug":"easy-cron-jobs-to-backup-your-website","status":"publish","type":"post","link":"https:\/\/www.smekdigital.com\/easy-cron-jobs-to-backup-your-website\/","title":{"rendered":"Easy CRON jobs to backup your Website"},"content":{"rendered":"
For WordPress sites, I recommend UpDraft Plus<\/a>\u00a0and use it on all my client’s sites flawlessly.<\/p>\n However, for non-Wordpress sites, your hosting company might provide a daily or weekly backup as part of your hosting package.<\/p>\n Regardless, it’s best practice to setup a secondary backup system that will keep multiple copies of your database (if applicable) and files.<\/p>\n <\/p>\n <\/p>\n Screenshots are from a Site5 control panel<\/strong><\/p>\n <\/p>\n TIP:<\/strong> The cron environment is different than the SSH environment and “#” \/ “%” characters are interpreted as a comment character. In order to solve this matter, you will need to escape each “%” with a backslash. (Thanks Florin M.)<\/p><\/blockquote>\n Objective:<\/strong> Add a CRON job to create a Tar Gzip file that will use the current date and time in the file’s name. This file will also be saved in a folder called “FILES-backup”.<\/p>\n This command will tar all files in the public_html folder and create an archive in the FILES-backup folder using today’s date\/time.<\/p>\n <\/p>\n Objective:<\/strong> Add a CRON job to create a SQL file that will use the current date and time in the file’s name. This SQL file will be saved in a folder called “DB-backup”.<\/p>\n This command will dump a MYSQL database in the FILES-backup folder using today’s date\/time.<\/p>\n In this example, your hosting username and password (usually same login as your Cpanel or web hosting) is Jimmy \/ JimmyPW,<\/p>\n and your database name is JimmyDB,\u00a0and the resulting file will be saved in the DB-backups folder.<\/p>\n <\/p>\n NOW go back that thang up!!<\/strong><\/p>\n I’ll revise this post later to add commands to only keep certain date ranges.<\/p>\n <\/p>\n http:\/\/www.mkyong.com\/linux\/linux-how-to-gzip-a-folder\/<\/p>\n https:\/\/stackoverflow.com\/questions\/4536376\/generate-backup-file-using-date-and-time-as-filename<\/p>\n Backup and Restore MySQL Database Using mysqldump<\/a><\/p><\/blockquote>\nFiles Backup Cron Job<\/h2>\n
\n
\nIn this example I created a folder called “FILES-backup”<\/li>\ntar -zcf FILES-backup\/\"$(date '+\\%m-\\%d-\\%y').tar.gz\" public_html<\/code><\/p>\n
Database Backup Cron Job<\/h2>\n
\n
\nIn this example, I created a folder called “DB-backup”<\/li>\nmysqldump -u Jimmy -pJimmyPW JimmyDB > DB-backups\/$(date +\\%m-\\%d-\\%Y-\\%H.\\%M.\\%S)-JIMMY-db.sql<\/code><\/p>\n
Technical References:<\/h3>\n