-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackup.sh
More file actions
executable file
·64 lines (56 loc) · 1.56 KB
/
backup.sh
File metadata and controls
executable file
·64 lines (56 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/sh
#
# $Id: backup.sh,v 1.2 2013/08/24 23:19:22 jepace Exp $
#
# backup.sh
#
# TODO:
# Deal with zfs filesystems not mounted in /pool
# Skip filesystems I don't want backed up
# More error checking
# Pretty fancy to auto generate a list, but stupid to then test to
# remove most of them...
# Dump databases: pg_dumpall > postgresql-YYMMDD.sql
#
#set -x
DIR=/pool
SRC=CVS_Repository
TAR=/usr/bin/tar
TARFLAGS="-cyp"
DESTDIR="$DIR/Backup"
DATE=`date +%y%m%d`
ZFSLIST="zfs list -H -t filesystem -o name"
ZFSSNAP="zfs snapshot"
for filesystem in `$ZFSLIST`
do
if [ "$filesystem" == "pool" ] || \
[ "$filesystem" == "pool/tmp" ] || \
[ "$filesystem" == "pool/VirtualDrives" ] || \
[ "$filesystem" == "pool/X" ] || \
[ "$filesystem" == "pool/X2" ]
then
echo "Skipping $filesystem..."
continue
fi
echo "** Processing $filesystem..."
zfs destroy $filesystem@$DATE > /dev/null 2>&1
$ZFSSNAP $filesystem@$DATE
if [ $? -ne 0 ]
then
echo "zfs snapshot failed. (Are you root?)"
exit 1
fi
# Make a tarball of some critical systems
if [ "$filesystem" == "pool/CVS_Repository" ] || \
[ "$filesystem" == "pool/www" ]
then
FS=`basename /$filesystem`
cd /$filesystem/.zfs/snapshot/$DATE
echo "Creating $DESTDIR/$FS-$DATE.tar.bz2"
$TAR $TARFLAGS -f $DESTDIR/$FS-$DATE.tar.bz2 .
fi
# zfs destroy $filesystem@$DATE
done
# Snapshot pool/Backup at the end of this, not the beginning
zfs destroy pool/Backup@$DATE
$ZFSSNAP pool/Backup@$DATE