Go Back   The macosxhints Forums > OS X Help Requests > UNIX - General



Reply
 
Thread Tools Rate Thread Display Modes
Old 02-26-2007, 10:49 PM   #1
saltydog4791
Prospect
 
Join Date: Jan 2002
Posts: 43
rsync by mtime

Hello all,

Stumped a little with what I am trying to do. I backup all my files once a month to some drives that I keep offsite. I would like to do daily backups to another drive at home so I have some kind of disaster recovery within the month. I have tried the following which seems to work on my os x box but I also need this to run on an ubuntu fileserver. For some reason the following will not work on the fileserver. Does anyone know of an alternate approach that might work? This is what I am trying to work with:

rsync --files-from=<(find src -mtime -1 -print) src dest

I can't think of any other way to do this. I would like to mirror the directory structure if at all possible. Thanks to anyone who has some clues.

mike
saltydog4791 is offline   Reply With Quote
Old 03-03-2007, 08:04 PM   #2
lar3ry
Prospect
 
Join Date: Mar 2007
Posts: 19
Look at the rsync manual page for --backup and --backup-dir -- these allow you to create daily incremental backups.

It's not automatic--you'll need to add some logic to create the incremental directories. (SMP: It's a "S"imple "M"atter of "P"rogramming...)

Here's some pseudo-code I use for my daily hotbackup and network backup scripts:

- Create BACKUP_DIR/inc/2007/03/03
- rsync -avz --delete --backup --backup-dir=BACKUP_DIR/inc/2007/03/03 from_dir/ to_dir/

This will do the following:

- Make "to_dir/" a mirror copy of "from_dir/" every day

- If a file is changed or deleted from the old "from_dir/", it will be copied to the same file structure within "BACKUP_DIR/2007/03/03" (today's date). Example: Assume "from_dir/dir1/dir2/dir3/file3" changes between yesterday and today. The new value will be found in "to_dir/dir1/dir2/dir3/file3" as expected, but the old contents will be found at BACKUP_DIR/2007/03/03/dir1/dir2/dir3/file3"

You will need either a large backup drive or put into place some method of pruning the daily backups you don't need (do you need daily incrementals from six months ago?).

Also note that if you copy disconnected sets of folders, you'll need some naming convention. For example, let's say that I backup /Applications, /Library, and my home directory /Users/lar3ry every day. I'd need to run rsync three times as follows:

Code:
$ rsync -avz --backup --backup-dir=/Volumes/Back/2007/03/03 /Applications/ /Volumes/Back/Applications/

$ rsync -avz --backup --backup-dir=/Volumes/Back/2007/03/03 /Library/ /Volumes/Back/Library/

$ rsync -avz --backup --backup-dir=/Volumes/Back/2007/03/03 /Users/lar3ry/ /Volumes/Back/Users/lar3ry/
You'll want to make sure you change the name of the incremental directory every day... this can be done using the "date +%Y/%m/%d" command.

My own personal script is written in perl and works the way I describe. It's saved my butt a number of times. Also note that rsync allows you to backup over the network, which can give you more flexibility:

- If you back up, make sure you back up to a different system (preferable), drive, or (at least) partition. Backing up onto the same drive/partition won't save you when the drive goes bad.

- USB and Firewire drives are great for backup/archival purposes. Use them!

- DoSomethingWhen (DSW) can be used to have a backup happen automatically once a USB drive becomes available to OS X. In other words, simply turn on your drive and DSW will start your backup for you.

- There are some good "network drives" available nowadays that might be perfect for off-system backup. Most use Windows file systems, so you might lose resource forks, etc, but it's better than losing data.

lar3ry
lar3ry is offline   Reply With Quote
Old 03-05-2007, 11:38 AM   #3
Squirtypoo
Triple-A Player
 
Join Date: Jan 2007
Posts: 72
I'm confused. What's the reason you can't you use 'rsync -a --delete-after src dest'? This will mirror the directory structure and preserve the files' metadata.
Squirtypoo is offline   Reply With Quote
Old 03-06-2007, 01:32 PM   #4
saltydog4791
Prospect
 
Join Date: Jan 2002
Posts: 43
Thanks for your replies guys. Is there a way I can get this to work for just backing up what has changed since the last full backup? I only want to backup the changes since the last full backup while retaining the right directory structure.
saltydog4791 is offline   Reply With Quote
Old 03-06-2007, 08:51 PM   #5
cpragman
All Star
 
Join Date: Jan 2004
Location: Limerick, PA
Posts: 858
I did this a while ago using a version of tar (I named it hfstar) that respected hfs (that might have been rolled into the base tar since then). Instead of trying to figure out how to name a backup based on a specific date/time, I used the system's aproach of just rotating the files.
Attached Files
File Type: sh userbackup.sh (1.3 KB, 141 views)
cpragman is offline   Reply With Quote
Old 03-07-2007, 04:02 AM   #6
Squirtypoo
Triple-A Player
 
Join Date: Jan 2007
Posts: 72
Quote:
Originally Posted by saltydog4791
Thanks for your replies guys. Is there a way I can get this to work for just backing up what has changed since the last full backup? I only want to backup the changes since the last full backup while retaining the right directory structure.

I thought the default behaviour of rsync only copied incremental changes?

Last edited by Squirtypoo; 03-07-2007 at 04:20 AM.
Squirtypoo is offline   Reply With Quote
Old 03-07-2007, 04:36 PM   #7
lar3ry
Prospect
 
Join Date: Mar 2007
Posts: 19
Quote:
Originally Posted by saltydog4791
Thanks for your replies guys. Is there a way I can get this to work for just backing up what has changed since the last full backup? I only want to backup the changes since the last full backup while retaining the right directory structure.

What this will do is keep the "BACKUP_DIR" set to an up-to-date mirror of your files, only copying the files that changed since the last time you ran your backup. The files that were changed between the two dates will be placed into the "incremental" folder named with the date/time in my example. Thus, the changes between two backups can be found in the dated directories (in the proper directory structure), and BACKUP_DIR will always contain the latest versions of all the files.

rsync will only copy the files that changed between runs.
  • The first time you run the script (when nothing is in the destination), the rsync command will copy every file to the destination folder and the dated directories will be empty.
  • The second time you run it, it will only copy those files that changed since the first run, making the destination folder completely up to date, and all changes between the first run and the second run in the dated folder.
  • The third time you run it, it will again only copy those files that changed since the second run, once again making the destionation folder up to date and putting the changes between the second run and the third run into the dated folder.

Here is a script to get you started. You will almost definitely need to tweak this:

Code:
#! /bin/sh

BACK_DRIVE="/Volumes/BackupDrive"
DIRS="/Applications /Users/userName"

FULL_DIR="$BACK_DRIVE/Full"

INC_DIR="$BACK_DRIVE/`date +%Y-%m-%d`"

for i in $DIRS
do
    rsync -az --backup --backup-dir="$INC_DIR" "$i/" "$FULL_DIR/$i/
done
There are many options that can be added, but this should be a start.

This script assumes the following:
  • Your backup drive is /Volumes/BackupDrive
  • You wish to back up the /Applications folder and your HOME folder (/Users/userName).
  • Your full backup would be found at
    • /Volumes/BackupDrive/Full/Applications (your system applications folder)
    • /Volumes/BackupDrive/Full/userName (your HOME folder)
  • Your incremental backup would be found at
    • /Volumes/BackupDrive/2007-03-07/Applications (changes to your applications folder)
    • /Volumes/BackupDrive/2007-03-07/userName (changes your HOME folder)

I hope this explains things better than I did the first time.
lar3ry is offline   Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 05:46 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.