Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
personal:portfolio:rsync-python-script [2014/07/26 20:20]
antonello created
personal:portfolio:rsync-python-script [2024/02/12 10:23] (current)
antonello Updated to Python3 (just print function). Tested working in Ubuntu 22.04
Line 1: Line 1:
 ====== Rsync Python script ====== ====== Rsync Python script ======
  
-A Python script to wrap rsync to have rolling backups for the latest n days, deleting the old ones. Nice because in this approach rsync uses hard links to build incremental backups that appear as full backups.+A Python script that wraps rsync to have rolling backups for the latest n days, deleting the old ones. Nice because in this approach rsync uses hard links to build incremental backups that appear as full backups. 
 + 
 +Of course it needs to be run under cron. 
 Fur the actual rsync call that is used in this script see [[http://www.sanitarium.net/golug/rsync_backups_2010.html]] Fur the actual rsync call that is used in this script see [[http://www.sanitarium.net/golug/rsync_backups_2010.html]]
  
Line 22: Line 25:
   maxbkps_d = 0   maxbkps_d = 0
      
-  print "** INFO: Starting rsync backup of "+basedir+" to "+bkpsdir+" - "+str(now.year)+"."+str(now.month)+"."+str(now.day)+" "+str(now.hour)+":"+str(now.minute)+  print("** INFO: Starting rsync backup of "+basedir+" to "+bkpsdir+" - "+str(now.year)+"."+str(now.month)+"."+str(now.day)+" "+str(now.hour)+":"+str(now.minute))
      
   # If a complete backup for today already exists I remove it as I can't create an incremental of itself..   # If a complete backup for today already exists I remove it as I can't create an incremental of itself..
Line 34: Line 37:
     if (parts[0] == bkpsbase):     if (parts[0] == bkpsbase):
       if len(parts) != 2:       if len(parts) != 2:
-        print "**** ERROR: There is a problem with a directory starting with bkpsbase but not having the date elements.. ("+bkpdir+")"+        print("**** ERROR: There is a problem with a directory starting with bkpsbase but not having the date elements.. ("+bkpdir+")")
       else:       else:
         de = parts[1].split('-') # date elements         de = parts[1].split('-') # date elements
         if len(de) != 3:         if len(de) != 3:
-          print "**** ERROR: There is a problem with a directory having a subset of the date elements.. ("+bkpdir+")"+          print("**** ERROR: There is a problem with a directory having a subset of the date elements.. ("+bkpdir+")")
         else:         else:
           # removing old bkps           # removing old bkps
Line 68: Line 71:
      
   if (maxbkps_y == 0): # first backup   if (maxbkps_y == 0): # first backup
-    print "** INFO: Performing first backup of the serie.."+    print("** INFO: Performing first backup of the serie..")
     bkpcommand2 = "rsync --archive --one-file-system --hard-links "     bkpcommand2 = "rsync --archive --one-file-system --hard-links "
     bkpcommand2 += "--human-readable --inplace --numeric-ids --delete "     bkpcommand2 += "--human-readable --inplace --numeric-ids --delete "
Line 86: Line 89:
   os.system(bkpcommand3)   os.system(bkpcommand3)
      
-  print "** INFO: rsync backup completed - "+str(now.year)+"."+str(now.month)+"."+str(now.day)+" "+str(now.hour)+":"+str(now.minute)+  print("** INFO: rsync backup completed - "+str(now.year)+"."+str(now.month)+"."+str(now.day)+" "+str(now.hour)+":"+str(now.minute)
  
 +~~DISCUSSION~~
  
personal/portfolio/rsync-python-script.1406398839.txt.gz · Last modified: 2018/06/18 15:10 (external edit)
CC Attribution-Noncommercial-Share Alike 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0