Automating Snapshots

This guide provides the steps to automate snapshots in a Triton Datacenter using Unix-like system's cron jobs, streamlining the task and ensuring regular creation of your instance snapshots.

Automating Snapshots in Triton Datacenter

Automating the creation of snapshots in the Triton Datacenter is a practical way to ensure regular backups of your instances without the need for manual intervention. This guide will take you through a simple process of setting up a cron job on a Unix-like system to automate the snapshot creation.

  1. Log In to Your Server Log into your server where you have Triton-CLI installed and configured with SSH or any method you usually use.

  2. Open Crontab Once you're logged in, open your crontab file by typing the following command:

    crontab -e
  3. Schedule a Cron Job Now, you'll need to schedule a cron job that will run the snapshot creation command at regular intervals. Below is an example of a cron job that creates a snapshot every day at 1:00 AM. Remember to replace <instance_id> and <snapshot_name_prefix> with your own details.

    0 1 * * * /usr/local/bin/triton instance snapshot create <instance_id> <snapshot_name_prefix>_$(date +\%Y\%m\%d\%H\%M\%S)

    This command appends a timestamp to the snapshot name to avoid naming conflicts and to help you identify when the snapshot was created.

  4. Save and Exit Once you've added the cron job, save and exit the crontab. The exact command to do so will depend on the text editor you're using.

  5. Verify the Cron Job To verify your cron job has been set up correctly, you can display the list of your cron jobs by typing:

    crontab -l

    You should see the snapshot creation cron job in the list.

This process will now automate the creation of snapshots for the specified instance at the time you've set. However, keep in mind that this is not a complete backup solution and should be used in combination with other data protection strategies.

Further automation

Automating the creation of snapshots in the Triton Datacenter can be conveniently done using a script that is scheduled to run at regular intervals. This method further streamlines the process, requires minimal manual intervention, and ensures regular and consistent snapshots. Below, we provide a sample script which you can adapt to your needs.

This script automatically creates a new snapshot and manages the retention of these snapshots, deleting the older ones that exceed the specified limit. The snapshots are logged for reference and any issues that might occur during the process.

This is an example script, please review and test thourougly before using.

instance_uuid=$(mdata-get sdc:uuid)
export TRITON_URL=""
export TRITON_ACCOUNT=<portal login>

# How many snapshots to keep. 
# This will remove snapshots more than this many

# log file location

export TRITON_PROFILE="env"
export TRITON_KEY_ID="$(ssh-keygen -l -f $HOME/.ssh/ | awk '{print $2}')"
keep=$(expr $keep_count + 1)

exec >> "${log_file}"
exec 2>&1

echo "==== STARTED $(date +'%Y%m%d_%H%M') ===="
triton instance snapshot create -w --name="$(date +'%s')" "${instance_uuid}"

# Get snapshots more than keep_count
for snap_name in $(triton instance snapshot list "${instance_uuid}" | sed -n '1!p' |\
  sort -nr -k1 | awk '{ print $1 }' | tail -n +${keep}); do
  triton instance snapshot delete -f -w "${instance_uuid}" "${snap_name}"
echo "==== FINISHED $(date +'%Y%m%d_%H%M') ===="
echo ""

Last updated