Be aware this is going to be ugly because I have never written anything in python and am attempting to quickly pick up just enough to solve my problem. I need a way to automate doing about 2 weeks of daily archives of a backup file. I think I have the logic down and have hacked together some code from the help files and some web searches, but I am sure it is not quite right yet. I am still hacking away at it but I figured it was worth asking here for some help too. Here is what I have so far:
#!/usr/bin/env python import commands,shutil #get the day of the month as an int in the range of 1-31 using a bash command to use in filenames day=int(commands.getoutput('date "+%d"')) #drop the latter half of the month by 15 since I only need 2 weeks of backups if [ "$day" > "15" ]; then day -= 15 fi #create my source and destination filenames using the day number to cycle the files sfn = r"/volumes/Storage/MediaNet/*saveset.bck" dfn = r"/volumes/Storage/MediaNet/.bck/" + str(day) + r"backup.bck" #copy the file into the backup directory shutil.copy(sfn, dfn)
I am sure my syntax is off and if anyone knows a better way to do the same thing I would gratefully accept any input. Thanks for taking the time to help.