{"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":"

Two easy CRON jobs that will have you feeling confident that your files are backed up!<\/h2>\n

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

\"cron-job\"\"CRON-job-common-settings\"<\/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

Files Backup Cron Job<\/h2>\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

    \n
  1. Create a folder (NOT in the public_html or www folder) to save the backup files. Make sure it’s a level up from your web folder!
    \nIn this example I created a folder called “FILES-backup”<\/li>\n
  2. Add CRON job command and select the interval. Test CRON job and verify file creation.<\/li>\n<\/ol>\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

    tar -zcf FILES-backup\/\"$(date '+\\%m-\\%d-\\%y').tar.gz\" public_html<\/code><\/p>\n

     <\/p>\n

    Database Backup Cron Job<\/h2>\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

      \n
    1. Create a folder (NOT in the public_html or www folder) to save the backup files. Make sure it’s a level up from your web folder!
      \nIn this example, I created a folder called “DB-backup”<\/li>\n
    2. Add CRON job command and select the interval. Test CRON job and verify file creation.<\/li>\n<\/ol>\n

      This command will dump a MYSQL database in the FILES-backup folder using today’s date\/time.<\/p>\n

      mysqldump -u Jimmy -pJimmyPW JimmyDB > DB-backups\/$(date +\\%m-\\%d-\\%Y-\\%H.\\%M.\\%S)-JIMMY-db.sql<\/code><\/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

      Technical References:<\/h3>\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>\n