Automating Backups: Mac

The following scripts are supplied to illustrate how it is possible to automate the backup of CatDV preferences and a MySQL database. They are free to use and modify but are provided for use at your own risk. Please consult a systems administrator if you are in any doubt about your backup and recovery strategy.

This tutorial is focused on OSX environments only.

As with any backup strategy there is no substitute for regular testing that backups are stored and can be recovered correctly. Disaster recovery tests are strongly recommended.

Knowledge of scripting will be needed to adapt these scripts to suit a specific environment or business needs.

Each script creates a folder on the Desktop called CatDVBackups with the sub-folders:

serverprefs
clientprefs
workerprefs
database

It then copies and date stamps the files into the corresponding subfolder.

There are comments in each script to help indicate what each section does and suggestions on where modifications can be made. It is possible  to automate these scripts to run to a schedule using task scheduling features within OSX, below are links indicating how to do this:

Launchd in Macintosh environments is described here

Macintosh shell script

Copy and paste the text of the script section at the bottom of this page into a text file and save it as catdv_backup.sh on the Desktop

or download the file here and rename the extension to .sh  CatDV_backup.txt

 Open terminal and the type

cd Desktop

chmod +x catdv_backup.sh

this makes the file executable

to run   type

./catdv_backup.sh

in the terminal and hit enter

If the  file name is changed to catdv_backup.command  the command can be  run in future by  double clicking the file – please  note  it must be  run once  as a .sh  before this  will work

for automation it should be left as a .sh extension   but a copy can be made and set to the .command extension for manual use.

#!/bin/sh
# shell script to back up key CatDV preferences files
# -- Set the window title --
# title='shell script to back up key CatDV preferences files'
# echo "33]0;$title07"
# -- Set the paths and folder names --
# to change the name of the backup folder Type the name below in place of CatdvBackups
# (no more than 30 characters alphanumeric with no white space)
# (this will be automatically substituted throughout the rest of the script)
Bfolder='CatDV_Backups'
# to modify the location of your backup folder change the path by replacing
# the string %HOMEPATH%Desktop with the preferred path
# (this will be automatically substituted throughout the rest of the script)
Bpath='Desktop'
# set the path to your mysql installation
MYSQLpath=/usr/local/mysql/bin/
#set the user name for the logged on user
$USERNAME=alastair
# echo the output folder
echo $HOME
echo $Bpath
echo $Bfolder
echo $Bpath/$Bfolder
# Create Directories at backup target
# Change folder to Backup path
cd $HOME
cd $Bpath
pwd
# Make a folder named by the variable $Bfolder
mkdir $Bfolder
# Change folder to $Bfolder and then make sub folders
cd $Bfolder
mkdir serverprefs
mkdir clientprefs
mkdir workerprefs
mkdir Database
# Copy the files and date + timestamp the backups --
cp /usr/local/catdvServer/catdv.properties /CatDV_Backups/serverprefs/catdv`date +%Y-%m-%d-%H.%M`.properties
cp $HOME/Library/Application Support/worker.xml /$HOME/Desktop/CatDV_Backups/workerprefs/worker`date +%Y-%m-%d-%H.%M`.xml
cp /Users/$USERNAME/Library/Application Support/workset.xml /$HOME/Desktop/CatDV_Backups/workerprefs/workset`date +%Y-%m-%d-%H.%M`.xml
cp /Users/$USERNAME/Library/Preferences/CatDV Preferences /$HOME/Desktop/CatDV_Backups/clientprefs/CatDV`date +%Y-%m-%d-%H.%M` Preferences
# Backup the mysql database and date + timestamp the backups --
/usr/local/mysql/bin/mysqldump -u catdvadmin -pcatdv catdv > /$HOME/Desktop/CatDV_Backups/Database/backup-`date +%Y-%m-%d`.sql