Backup repozytorium
Znalazłem na sieci śliczny skrypcik do archiwizowania repozytorium svn:
#!/usr/bin/python
# script to backup SVN repos at a given time from the last revision number
# Greg Loscombe
import os
import sys
debug = 0
# build a list of projects and what the last revision backup
basedir = "/home/subversion/basedir"
basebackup = "/var/log/svnbackup"
revlogfile = "/var/log/svnbackup/last_rev"
projects = {}
something_dumped = 0
def get_youngest(proj):
youngest_cmd = "/usr/bin/svnlook youngest " + basedir + proj
if ( debug == 1):
print "command:", youngest_cmd
cmdout = os.popen( youngest_cmd )
rev_youngest = cmdout.read()
rev_youngest = int( rev_youngest.strip() )
cmdout.close()
return rev_youngest
def dump_incremental(base, proj, rev_from, rev_youngest):
location = base + proj + ".dump." + str( rev_from ) + "-" + str(rev_youngest )
if ( debug == 1):
print "Location dumped too", location
incremental = "/usr/bin/svnadmin dump --incremental " + basedir + this_proj + " -r " + str( rev_from ) + ":" + str( rev_youngest ) + " > "+ location
cmdout = os.popen( incremental )
cmdout.close()
if ( debug == 1):
print "Command incremental dump:-", incremental
def update_log():
revfile = file( revlogfile, "w")
for this_proj in projects.iterkeys():
revfile.write( this_proj + " = " + str(projects[this_proj]) + "\n")
if ( debug == 1):
print "New log:-", this_proj + " = " + str(projects[this_proj]) + "\n"
print this_proj + " = " + str( projects[this_proj] )
revfile.close()
def update_error_log(message):
errorfile = file( "/var/log/svnbackup/error_log", "a")
errorfile.write( message )
#errorfile.write( proj + ":" + str( updated_rev ) + ":" + message )
#add more stuff here soon
errorfile.close()
#def update_access_log(message):
#this will print things like last run etc
# main part now, lets get all the old revision numbers we backed up
revfile = open( revlogfile )
while 1:
line = revfile.readline()
if line == "":
break
if ( ( line.startswith("[") or line.startswith("#") ) is False ):
proj, last_rev = line.split(' = ')
last_rev = last_rev.strip()
projects[proj] = int(last_rev)
revfile.close()
# lets get the new youngest and compair, if its newer, then do a incremental dump
# if its older than the last log, we have a problem, log it
# if its the same nothing happens
# if its never been dumped, time for a full dump
for this_proj in projects.iterkeys():
rev_youngest = int( get_youngest(this_proj) )
rev_old = int( projects[this_proj] )
if ( debug == 1 ):
print "this project", this_proj, "old revision", rev_old, "youngest", rev_youngest
if ( rev_old > rev_youngest ):
errmessage = "logged backed up revision " + str(rev_old) + " > youngest current revision " + str(rev_youngest) + "\n"
#update_error_log(this_proj, rev_youngest, errmessage)
update_error_log(errmessage)
elif ( rev_old == 0 ):
print "First time dump, do it all for", this_proj, "upto", rev_youngest
dump_incremental(basebackup, this_proj, 0, rev_youngest)
something_dumped = something_dumped + 1
projects[this_proj] = int(rev_youngest)
elif ( rev_old < rev_youngest ):
print "Update for project", this_proj, "upto", rev_youngest
rev_from = rev_old + 1
dump_incremental(basebackup, this_proj, rev_from, rev_youngest)
something_dumped = something_dumped + 1
projects[this_proj] = int(rev_youngest)
elif ( rev_old == rev_youngest ):
print "Revisions have not changed for project", this_proj
# if something changed then its time to update the last logged file
if ( something_dumped > 0 ):
print something_dumped, "repos have changed since last dump"
update_log()
else:
print "Nothing has changed, nothing done"
# the end
W pliku /var/log/svnbackup/last_rev należy umieścić nazwę repozytorium i numer ostatniej zarchiwizowanej wersji, np.:
/jaxmpp = 0
/proplan = 0
Całość dodać można sobie do crona, i już mamy eleganckie, przyrostowe backupy repozytorium.


Komentarze do wpisu
Możesz śledzić odpowiedzi poprzez kanał RSS. Możesz dodać komentarz lub zostawić ślad (trackback) ze swojego bloga.
PeTe
Jakoś nie mam zaufania do przyrostowych backupów. Wolę robić hotcopy...
25 kwietnia 2005, 11:21:48
bmalkow
A czemu, jeśli wolno spytać?
Ja cały czas robię dumpy i kilka razy już mi czteryLitery uratowały. Przyrostowych nie robiłem, bo nie chciało mi się ręcznie sprawdzać numerów wersji.
25 kwietnia 2005, 12:23:57
PeTe
Dumpy to i ja robię, a do przysrostowych ogólnie mam uprzedenie, ponieważ miałem kiedyś problem z odtworzeniem ponieważ skopał się jeden z wczesnych przyrostowych bacupów i później już reszta nadawała się do kosza... A robiąc pełny backup na każdej tasiemce masz pełną kopię...
25 kwietnia 2005, 13:10:39
Dodaj komentarz