Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
personal:portfolio:rsync-python-script [2014/07/26 20:23] antonello |
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 that 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. | Of course it needs to be run under cron. | ||
Line 25: | Line 25: | ||
maxbkps_d = 0 | maxbkps_d = 0 | ||
| | ||
- | print "** INFO: Starting rsync backup of " | + | print("** INFO: Starting rsync backup of " |
| | ||
# 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 37: | 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.. (" | + | print("**** ERROR: There is a problem with a directory starting with bkpsbase but not having the date elements.. (" |
else: | else: | ||
de = parts[1].split(' | de = parts[1].split(' | ||
if len(de) != 3: | if len(de) != 3: | ||
- | print "**** ERROR: There is a problem with a directory having a subset of the date elements.. (" | + | print("**** ERROR: There is a problem with a directory having a subset of the date elements.. (" |
else: | else: | ||
# removing old bkps | # removing old bkps | ||
Line 71: | 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 += " | bkpcommand2 += " | ||
Line 89: | Line 89: | ||
os.system(bkpcommand3) | os.system(bkpcommand3) | ||
| | ||
- | print "** INFO: rsync backup completed - " | + | print("** INFO: rsync backup completed - " |
~~DISCUSSION~~ | ~~DISCUSSION~~ | ||