Automating Backup Script

The following covers optional automation of backups with Cron.

In this example, the flag -e is used with the backup script and the example password of "supersecretpassword" is used to encrypt the backups. Additionally, the -d flag is used to delete any quantity of backup files over 30 giving 30 days of files. It is recommended to mount a file system path to an S3 bucket and have the backups generated automatically to an S3 bucket.

To automate the backups, do the following:

  1. Edit the /etc/crontab file to schedule the tasks:
    # vim /etc/crontab
  2. Enter the schedule that you would like to run.

    In this example, we have two entries. One to create the backup that will run at 1AM system time, and another to delete more than 10 log files that runs at 2AM system time.

    #Run Backup
    * 1 * * * root /opt/PrimeKey/support/system_backup.sh -e supersecretpassword
    #Prune backups after 10 total
    * 2 * * * root /opt/PrimeKey/support/system_backup.sh -d 30
  3. To output these entries to log files of their own for testing and validation, use the following entries:
    #Run Backup and log to file
    * 1 * * * root /opt/PrimeKey/support/system_backup.sh -e supersecretpassword >> /var/log/cron.log 2>&1 
    #Prune backups after 10 total and log to file
    * 2 * * * root /opt/PrimeKey/support/system_backup.sh -d 30 >> /var/log/cron2.log 2>&1