Backup Script

I’m trying to come up with a backup script that will only copy the files that have changed during the day to my portable hard drive.

I’d got the following:-

cp 'find /home/chris/Documents/Email/ -mtime -1 -type f -print' /home/chris

which doesn’t seem to work.

Where as if I use tar it works. I don’t want it in a tar file, I want it to save (and overwrite the files) in a directory.

What am I doing wrong?

I can do you one in vbs, but it’d be useless on a linux box

I’ve done something similiar. Here is a snippit of code (C shell) that I use at work. Fortunately, I have a copy at home (that I can share).

In my scheme, LOGS is a collection of log files (that is sorted). I notice that you follow your directory with a “/” (separator). I don’t know if that accounts for your script not working.

set LOGS = find /var/log_dir -name "AUDIT_*" -mtime -$DAYS | sort

set FILES = ($LOGS $CURRENT_LOG)
foreach FILE ($FILES)
echo — FILE: $FILE
grep “FAILED LOGIN” $FILE
end

…You’re not using a single quote (’) right?
Where you need one of these (`) …(I forget its name!).

[QUOTE=Tom Wilson;372942]
…You’re not using a single quote (’) right?
Where you need one of these (`) …(I forget its name!).[/QUOTE]

Spotted the rookie error I believe :chin:

Yeah using a single quote not a back quote.:rolleyes:

EDIT:

Yep that worked with the right quote now. :doh: Cheers

Being a one line person I would have used

find /home/chris/Documents/Email/ -mtime -1 -exec cp -R {} /home/chris ;

Just be aware of the risks of writing straight to your home directory in case somebody wants to send you a new .rhosts file or something similar

[QUOTE=MrTFWitt;372963]Being a one line person I would have used

find /home/chris/Documents/Email/ -mtime -1 -exec cp -R {} /home/chris ;

Just be aware of the risks of writing straight to your home directory in case somebody wants to send you a new .rhosts file or something similar[/QUOTE]

Cheers TFW.
This was just a test TBH. The actual backup line would be

cp `find /home/chris/Documents/ -mtime -1 -type f -print` "/media/Portable HD"

to write only the changed document files to the portable hard drive.

I tried the -exec command but obviously got it wrong.

Dammit, doesn’t work as I want it to.

Basically I only want the files from My Documents to be transferred to the external drive. I also want the file structure preserved.

Using the above line, I get the errors because some of the folders under My Documents are My Music etc and it doesn’t like the gaps and it doesn’t preserve the file structure.

Am I just going to have to use tar command because as far I can see, tar doesn’t care less about the spaces and it preserves the structure.

You would have to use awk or similar to modify the output from the find command to do this I believe. Unfortunately can’t help you 'cos I’m useless at awk.

If you just want a mirror of the directory each night without copying everything why not use rsync?

There was a time when recursive copying was only possible with something like:

tar cf - source | ( cd dest ; tar xf - )

which may be more efficient than using find to build a file list for cp.

Not heard of Rsync. Maybe I should have searched for similiar before jumping in and deciding that a shell script was easiest option.

Reading up on rsync now :thumbsup: Looks like it’s exactly what I need. Thanks Martin!

Stupid me not to look for a nice simple option before trying to dive in. :rolleyes:

EDIT:

Looks like it’s working away. :slight_smile:
Nightly backup

rsync -a --delete /home/chris/Documents/ "/media/Portable HD/Backups/Documents/"

Rsync is quality I use it for cross-network nightly server backups here and its a beautiful tool. Useless *nix fact - it was written by the same bloke responsible for Samba, so his credentials are beyond dispute.

the cp -R above was to preserve directory structure.
Didn´t try it with spaces in filenames though.

Yeah it seemed to work for the files in the directory that didn’t have spaces in. I wouldn’t have spaces in but I’m still got part of it from Windows which adds My Music and My Pcitures by default.

Rsync is working fantastic. :smiley:
Cheers Martin.