LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Simple backup script (http://www.linuxquestions.org/questions/linux-newbie-8/simple-backup-script-452083/)

dotancohen 06-06-2006 08:11 AM

Simple backup script
 
I've been looking for a backup solution, and I'm not really happy with any software that I see. So I'm trying to find a variant of "cp" that would just copy everything in /home/user/ that has been changed in the past X days to /home/user/backup including hidden files. I would then just burn ~/backup to a CD-R. I can't get a handle on the syntax, though. How is this done?

Thanks.

crabboy 06-06-2006 08:57 AM

Change the -1 mtime option to adjust the modified date. -2 will be two days ago, -3 three days, etc... You'll want to do a fullbackup and

Putting the backup directory under /home/user creates a problem with the find. It's best not to put it there.

Code:

#!/bin/sh

NEWDIR="/tmp/backup"

for i in `find /home/user -type f -mtime -1`; do
  DIR=`dirname $i`
  DEST=$NEWDIR/$DIR
  mkdir -p $DEST
  cp -a $i $DEST
done

You may want to look at rsync using the timestamp options, even for local copies. It will be a bit more robust.

Electro 06-06-2006 12:22 PM

Use dar. I recommend using DVD instead of CD for backups because DVD disc includes ECC which CD do not have.

As with all backups, you will have to do a full backup so it can compare it to any modified or new files. Also test the backups on another system.

dotancohen 06-07-2006 07:00 PM

Thanks, this is just what I was looking for. I will play with tit a bit and make sure that I understand it in it's entirely.

Electro 06-07-2006 10:53 PM

I dislike when people do not or just skim posts. dar is a lot better than using cp or tar. dar can double or triple the size of a CD or DVD because you can set the minimum file size to compress and set which files to not compress. Instead of running scripts, you just specify the .darrc file.

dotancohen 06-17-2006 05:00 AM

Quote:

Originally Posted by Electro
I dislike when people do not or just skim posts. dar is a lot better than using cp or tar. dar can double or triple the size of a CD or DVD because you can set the minimum file size to compress and set which files to not compress. Instead of running scripts, you just specify the .darrc file.

Well, I'd rather use cp because I want to be able to access the individual files in case of need without restoring the entire backup. Usually, my needs are for only a few files.

Electro 06-17-2006 02:59 PM

dar can extract a file if you want to with out extracting the whole file.

dotancohen 06-18-2006 11:53 PM

Quote:

Originally Posted by Electro
dar can extract a file if you want to with out extracting the whole file.

I just spent some time looking at dar. While it seems an excellent program, for me it is most important that the data be stored in it's original form- only cp does that. If I have a text file, I want it stored as a text file.

Thanks for the suggestion, though.

Dotan Cohen


All times are GMT -5. The time now is 10:51 PM.