Apps :: 7 day file backup script?



Thanks to all for the ideas.

Specifically what I'm doing is once a day creating a zip file of a critical directory and then copying it over to a dedicated usb stick. I simply want to automate this process and maintain a week long archive.

It's been a long time since I wrote scripts so I'm quite rusty at interpreting what the offered examples do.  I'll start studying up but would appreciate a little more explanation as to how each example works. For instance I have no idea why the OSX script would be bad.

If I get what you mean, it can be something like (using easy-to-read/change variables to see what it does):
Code Sample
folder_to_backup="/path/to/myfolder"
backup_name="mybackupname"
backup_location="/path/to/mybackuplocation"

backup_name="${backup_name}-`date +%a`.tar.gz"
cd "$backup_location"
rm -f "$backup_name"
tar zcvf "$backup_name" "$folder_to_backup"
Basically this will use filenames based on the day of the week... and will remove last week's if it exists before making a .tar.gz out of your specified folder.

Quote
For instance I have no idea why the OSX script would be bad.
At first glance, I think it was a reference to the if-statements.

fyi: this seems more of a scripting thread than a mydsl one...?

Quote
I'm trying to backup a file once a day such that I have a weekly archive of the file...

is different from...
Quote
creating a zip file of a critical directory and then copying it over to a dedicated usb stick.


anyway...
Quote
I'm quite rusty at interpreting what the offered examples do.

And I thought I was too pedantic with my explanation of a rather simple script. I was under the impression from the first quote above that you wanted to create something like a weekly log of a particular file. Let me know what's unclear about either script I offered and I'll help knock some of your rust off.

^thehatsrule^ is right about the if statements and that this is in the wrong section and belongs in scripting.

Thanks for the script ^thehatsrule^.

OK, I deleted my previous response because it finally sank in how the script works. It just makes the name of the backup file whatever it is plus the day of the week and if it already exists deletes it. The backups will roll around the week with each day in the archive until the same day arrives a week later. Nice and simple. I must be a little thick today.

I do understand lucky13's scripts, I was referring to the OSX one. Thank you lucky13 for the examples.
Next Page...
original here.