Trim backup files a bit; make the emails a bit more verbose.
This commit is contained in:
parent
b5b4dafb6f
commit
4a1e5c660e
Notes:
svn2git
2021-03-31 03:12:20 +00:00
svn path=/head/; revision=254625
2 changed files with 24 additions and 12 deletions
|
@ -8,7 +8,7 @@ import zfs, commands, datetime, sys, os, bz2
|
|||
from signal import *
|
||||
|
||||
# List of filesystems to backup
|
||||
backuplist=["a", "a/nfs", "a/src", "a/local", "a/ports", "a/portbuild",
|
||||
backuplist=["a", "a/nfs", "a/local", "a/portbuild",
|
||||
"a/portbuild/amd64", "a/portbuild/i386",
|
||||
"a/portbuild/ia64", "a/portbuild/powerprc",
|
||||
"a/portbuild/sparc64"]
|
||||
|
@ -17,7 +17,7 @@ backuplist=["a", "a/nfs", "a/src", "a/local", "a/ports", "a/portbuild",
|
|||
backupdir="/dumpster/pointyhat/backup"
|
||||
|
||||
# How many days between full backups
|
||||
fullinterval=3
|
||||
fullinterval=9
|
||||
|
||||
def validate():
|
||||
fslist = zfs.getallfs()
|
||||
|
@ -48,8 +48,12 @@ class node(object):
|
|||
self.parent = None
|
||||
self.visited = 0
|
||||
|
||||
print "zbackup: starting at " + datetime.datetime.now().ctime()
|
||||
|
||||
for fs in backuplist:
|
||||
|
||||
print
|
||||
|
||||
dir = backupdir + "/" + fs
|
||||
mkdirp(dir)
|
||||
|
||||
|
@ -153,14 +157,14 @@ for fs in backuplist:
|
|||
|
||||
chain.reverse()
|
||||
|
||||
print chain
|
||||
print "chain is " + str( chain )
|
||||
|
||||
# Prune stale links not in the backup chain
|
||||
for j in backups.iterkeys():
|
||||
cur = backups[j]
|
||||
for k in cur.child:
|
||||
stale="%s-%s" % (cur.name, k.name)
|
||||
print "Deleting %s" % stale
|
||||
print "Deleting stale backup %s" % stale
|
||||
os.remove("%s/%s/%s" % (backupdir, fs, stale))
|
||||
|
||||
# Lookup date of full dump
|
||||
|
@ -186,7 +190,7 @@ for fs in backuplist:
|
|||
# zfs send aborts on receiving a signal
|
||||
signal(SIGTSTP, SIG_IGN)
|
||||
if not dofull:
|
||||
print "Doing incremental of %s: %s-%s" % (fs, latest, nowdate)
|
||||
print "Doing incremental backup of %s: %s-%s" % (fs, latest, nowdate)
|
||||
(err, out) = \
|
||||
commands.getstatusoutput("zfs send -i %s %s@%s | bzip2 > %s" %
|
||||
(latest, fs, nowdate, outfile))
|
||||
|
@ -202,9 +206,9 @@ for fs in backuplist:
|
|||
print "Error from snapshot: (%s, %s)" % (err, out)
|
||||
try:
|
||||
os.remove(outfile)
|
||||
print "Deleted %s" % outfile
|
||||
print "Deleted file %s" % outfile
|
||||
except OSError, err:
|
||||
print repr(err)
|
||||
print "OSError: " + repr(err)
|
||||
if err.errno != 2:
|
||||
raise
|
||||
finally:
|
||||
|
@ -214,10 +218,13 @@ for fs in backuplist:
|
|||
try:
|
||||
os.rename(outfile, "%s/%s/%s-%s" % (backupdir, fs, latest, nowdate))
|
||||
except:
|
||||
print "Error renaming dump file!"
|
||||
print "Error renaming dump file" + outfile + "!"
|
||||
raise
|
||||
|
||||
if dofull:
|
||||
for i in seen:
|
||||
print "Removing stale snapshot %s/%s" % (dir, i)
|
||||
os.remove("%s/%s" % (dir, i))
|
||||
|
||||
print
|
||||
print "zbackup: ending at " + datetime.datetime.now().ctime()
|
||||
|
|
|
@ -7,9 +7,7 @@ import zfs, commands, datetime, os
|
|||
# List of filesystems to expire
|
||||
expirelist=(("a", 14),
|
||||
("a/nfs", 14),
|
||||
("a/src", 14),
|
||||
("a/local", 14),
|
||||
("a/ports", 14),
|
||||
("a/portbuild", 14),
|
||||
("a/portbuild/amd64", 14),
|
||||
("a/portbuild/i386", 14),
|
||||
|
@ -18,7 +16,6 @@ expirelist=(("a", 14),
|
|||
("a/portbuild/sparc64", 14),
|
||||
("a/snap", 7),
|
||||
("a/snap/ports", 7),
|
||||
("a/snap/src-5", 7),
|
||||
("a/snap/src-6", 7),
|
||||
("a/snap/src-7", 7),
|
||||
("a/snap/src-8", 7),
|
||||
|
@ -27,8 +24,11 @@ expirelist=(("a", 14),
|
|||
("a/snap/world-i386-HEAD", 7))
|
||||
|
||||
now = datetime.datetime.now()
|
||||
print "zexpire: starting at " + now.ctime()
|
||||
|
||||
for (fs, maxage) in expirelist:
|
||||
print
|
||||
|
||||
try:
|
||||
snapdata = zfs.getallsnaps(fs)
|
||||
except zfs.NoSuchFS:
|
||||
|
@ -44,11 +44,16 @@ for (fs, maxage) in expirelist:
|
|||
try:
|
||||
snapdate = datetime.datetime.strptime(snap, "%Y%m%d%H%M%S")
|
||||
except ValueError:
|
||||
print "zexpire: don't know what to do with snap `" + snap + "'"
|
||||
continue
|
||||
|
||||
if (now - snapdate) > datetime.timedelta(days=maxage):
|
||||
print "Snapshot %s@%s too old" % (fs, snap)
|
||||
print "Snapshot %s@%s too old, attempting zfs destroy" % (fs, snap)
|
||||
(err, out) = commands.getstatusoutput("zfs destroy %s@%s" % (fs,snap))
|
||||
|
||||
if err:
|
||||
print "Error deleting snapshot", out
|
||||
|
||||
then = datetime.datetime.now()
|
||||
print
|
||||
print "zexpire: ending at " + then.ctime()
|
||||
|
|
Loading…
Reference in a new issue