Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 06-12-2005, 09:58 PM   #1
Registered: Jun 2004
Location: Texas
Distribution: Solaris 10 / Slackware 10.1
Posts: 68

Rep: Reputation: 15
rsync and cp -al for staggered backups

I have been given the task of setting up rsync to back up a server, fortunately all I have to do is set up rsync to backup one hard drive to another rather than actually 'remote' sync-ing.
I had to make a new backup everyday (incremental) and keep the data for up to 3 days: so after reading up on cp -al and rsync I wrote a little script based upon one i found online.

Mine reads as such:

rm -fr /mnt/backups/backup.threedaysold
mv /mnt/backups/backup.twodaysold /mnt/backups/backup.threedaysold
mv /mnt/backups/backup.yesterday /mnt/backups/backup.twodaysold
cp -al /mnt/backups/ /mnt/backups/backup.yesterday
rsync -av --delete --exclude "/mnt/backups" / /mnt/backups/

As you can see the root (/) dir is backed up into which is then hardlinked to yesterday which is moved to two etc and so on.
I ran it three times when I had the chance, and it 'worked', the first time it took a very very long time and I saw a copied filesystem under /mnt/backups/ I ran it twice more both of which ran significantly aster than the first time, but still took a while as it was backing up 12+gigs of data. I checked the filesizes/data used in /mnt/ and it said 35 gigs.

I then realized that i was reading links to actual files, so I ran du which said I had 13 gigs used, so it was working just as I hoped...except the fact I was using links made me realize that perhaps the files I have backed up are not actually there. What if I had a file two days ago, accidently deleted it yesterday, and realized I needed it today? Will going to the backup folder from two days ago actually give me the file or will I just find a hard link to nothing?
Excuse my ignorance, this is a completely CLI system, and though I am not a total n00b, I am not very adept at that interface (though I have made great strides lately) I am also quite ignorant when it comes to system administration.
Running the script enough times to test the system would take me hours, my headache at trying to completely understand what I am doinf is killing me ... plus I dont have access to the machine in question at the moment...
So could someone enlighten me to as what I am doing, and what (if anything) I can do to make the system better?
Old 06-13-2005, 01:53 AM   #2
Registered: Jul 2003
Location: Pennsylvainia
Distribution: Slackware / Debian / *Ubuntu / Opensuse / Solaris uname: Brian Cooney
Posts: 503

Rep: Reputation: 30
Understanding the differance between a hard link and a soft link might help

a soft link is like a web link.... if the file goes away, the link is "broken"

hard links are a little differnt. you cant "break them." If you have a hard link to a file, and you deleate the file, you dont actually loose that file unless you deleate the link too. It having another copy of the file, without using any more disk space

There may be a better way to do what your doing, but at least if you have hard links, you wont be loosing the file completley.

The only down side is, changing the file would change both copies too, so if you trash it in a text editor, your might have issues.
Old 06-14-2005, 12:24 AM   #3
Registered: Jun 2004
Location: Texas
Distribution: Solaris 10 / Slackware 10.1
Posts: 68

Original Poster
Rep: Reputation: 15
Thank you, it all makes so much more sense now.
I updated the script and ran it several times on my laptop (much smaller filesystem) and it works perfectly, soon I will copy it over to the server.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Rsync backups - how not to backup TV recordings jamespetts Linux - Software 0 11-20-2004 12:15 PM
Windows Rsync Upload to Linux Rsync - permissions inspleak Linux - Software 0 10-12-2004 02:49 PM
Backups with rdiff - how different from rsync? Donboy Linux - Software 1 07-30-2004 10:54 PM
Rsync for incremental backups? Phaethar Linux - Software 3 12-04-2003 01:27 PM
backups AZDAVE Linux - General 1 11-06-2003 12:05 PM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07:16 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration