Just added a new section to /etc/periodic/monthly/mine.monthly
in the attempt to create monthly backups of my subversion repositories, using compressed dump files:
[Update: Now using quoted variable names.] [Update: Now checking "format" file.]
if [ -d /Library/Repositories ]; then cd /Library/Repositories for i in * ; do # Not a subversion repository? Ignore it. if [ ! -f "$i/format" ]; then continue fi line="/tmp/monthly-$i.out" # File: /Volumes/Backups/Attic/svn-file-2014-01-17.dump.gz name="svn-$i-`date +%F`.dump.gz" dump="/Volumes/Backups/Attic/$name" if [ ! -f "$dump" ]; then echo "Dumping subversion repository: $name" # Dump into a gzipped file; "Dumped revision n" into temp file. { /usr/bin/svnadmin dump "$i" | gzip -c -9 > "$dump"; } >& "$line" # Change the user for the dump file. chown gollum:gollum "$dump" # Only output the last stderr line then delete the file. tail -1 "$line" rm "$line" else echo "Warning: Dump already exists: $name" fi done else echo "Error: Repositories directory not found." fi
N.B. I also use TrashLater to keep files for only 6 months in the Attic folder.
For /etc/periodic/weekly/mine.weekly
I only dump the most recently modified repository since I don't normally work on multiple projects. This is done with a different foreach loop, where we get just one repository file name:
if [ -d /Library/Repositories ]; then cd /Library/Repositories # List the dir by last modified and get the first entry only. for i in `ls -1t | sed '1 q'` ; do line="/tmp/weekly-$i.out" # [...as above...] done else echo "Error: Subversion repositories not found." fi