Comments on: Super-simple perl script for zfs snapshots http://writequit.org/blog/2007/06/01/super-simple-perl-script-for-zfs-snapshots/ Tu fui, ego eris Fri, 15 Aug 2014 11:26:27 +0000 hourly 1 http://wordpress.org/?v=4.1.5 By: fifthecho http://writequit.org/blog/2007/06/01/super-simple-perl-script-for-zfs-snapshots/comment-page-1/#comment-84 Tue, 16 Oct 2007 15:31:58 +0000 http://writequit.org/blog/?p=54#comment-84 Nice script! Thanks! Saved me a having to hash this out myself.

]]>
By: Ralf Ramge http://writequit.org/blog/2007/06/01/super-simple-perl-script-for-zfs-snapshots/comment-page-1/#comment-83 Tue, 05 Jun 2007 07:19:31 +0000 http://writequit.org/blog/?p=54#comment-83 Damn, looks like the blog software can’t handle it. Please delete the entry and feel free to contact me, I’ll send you the script by e-mail for inclusion in your blog.

]]>
By: Ralf Ramge http://writequit.org/blog/2007/06/01/super-simple-perl-script-for-zfs-snapshots/comment-page-1/#comment-82 Tue, 05 Jun 2007 07:17:18 +0000 http://writequit.org/blog/?p=54#comment-82 Here’s a simple quick&dirty script I wrote some time ago. Its status is definitely super-alpha, I would never use it as a crontab entry on my own servers and neither should you :-) But I think it can be useful as a demonstration for your readers.

I do *not* include an information of how to use it. The script is self-explanatory and someone who doesn’t understand it shouldn’t use it anyway, for his/her own sake ;-)


#!/bin/bash

# backup_zfssnap.sh, (c) 2007 ralf.ramge@webde.de

BACKUPDIR=”/export/backup/snapshots”
DSTAMP=`date ‘+%y%m%d-%H%M%S’`
FILESYS=$1
DEST=$2
REPLICA=$3
BACKUPNAME=`echo $FILESYS | sed ‘s/\//_/g’`
BACKUPFILE=$BACKUPNAME”-“$DSTAMP”.zfs”
SNAPSHOT=$FILESYS”@backup-“$DSTAMP

if [ ! -d $BACKUPDIR ]; then
echo “Backup Directory doesn’t exist”
exit 1
fi

cd $BACKUPDIR

# Check here if we have 7 backup files, create them if we don’t
COUNT_FILES=`ls -1 $BACKUPNAME* | wc -l`
if [ $COUNT_FILES -le 1 ]; then
for COUNT in 1 2 3 4 5 6 7
do
if [ ! -f $BACKUPNAME”-000000-00000″$COUNT”.zfs” ]; then
touch $BACKUPNAME”-000000-00000″$COUNT”.zfs”
sleep 1
fi
done
fi

# Check here that we have less than 8 backup files
COUNT_FILES=`ls -1 $BACKUPNAME* | wc -l`
if [ $COUNT_FILES -gt 7 ]; then
# echo “More than 7 backup files exist”
# exit 1
while [ $COUNT_FILES -gt 7 ]
do
OLDEST_BACKUP_FILE=`ls -rt1 $BACKUPNAME* | head -1`
rm $OLDEST_BACKUP_FILE
let COUNT_FILES=COUNT_FILES-1
done

fi

# Find the oldest backup file to delete
OLDEST_BACKUP_FILE=`ls -rt1 $BACKUPNAME* | head -1`

# Create the snapshot
zfs snapshot $SNAPSHOT

# Create a filesystem image in the local backup directory
zfs send $SNAPSHOT > $BACKUPDIR”/”$BACKUPFILE

# Check for $2 and, if exists, create a second copy on a remote host for tape archival
if [ ! -z $2 ]; then
`zfs send $SNAPSHOT | ssh root@$2 “cat >$BACKUPDIR/$BACKUPFILE”`
fi

# Check for $3 and, if exists, mirror the filesystem on the remote host
if [ ! -z $3 ]; then
`ssh root@$2 “zfs receive $3

]]>
By: thnetos http://writequit.org/blog/2007/06/01/super-simple-perl-script-for-zfs-snapshots/comment-page-1/#comment-80 Sun, 03 Jun 2007 18:35:34 +0000 http://writequit.org/blog/?p=54#comment-80 That would make sense, but in this case I don’t actually want to make snapshots of every filesystem, just the ones I specified. Definitely would be easy to add though.

]]>
By: Mark J Musante http://writequit.org/blog/2007/06/01/super-simple-perl-script-for-zfs-snapshots/comment-page-1/#comment-81 Sat, 02 Jun 2007 21:56:19 +0000 http://writequit.org/blog/?p=54#comment-81 You could go one step further, and loop over the output of ‘zpool list -H -o name’, and do a ‘zfs snapshot -r’. That would do all your filesystems for you at once.

]]>