2
I have written this backup script that looks in a file and copies recent files into a folder.
#!/usr/bin/bash
# the number of days to do the backup for.
days=2;
# the files to backup.
location[0]='/opt/location'
# the location to copy the file to
copyLocation='/users/me/Backup/firstBackupScriptTry'
# preform the back up
for i in ${location[*]}
do
find $i \! -name '*.class' -mtime -$days \! -type d -exec cp {} $copyLocation \;
done
It works but it is not that useful.
I would prefer the script to preserve the directory structure when it copies. Ie I would like it to do: cp -r from to
but only copy the recent files.
+1: helpful answer. I probably will end up using that, looks pretty good. However I am curious how to finish my script. Any ideas? – sixtyfootersdude – 2010-02-10T19:35:37.147
rsync -a --include "/" --include='.class' --exclude="*" /opt/location/ /users/me/Backup/firstBackupScriptTry – Justin Smith – 2010-02-10T20:53:34.720
which is to say that one line duplicates the whole of your script (instead of copying changes in the last two days, it copies all changes since last backup to the same location) – Justin Smith – 2010-02-10T20:55:14.683
Since it looks like you're backing up code, you should also consider the
-C
option for rsync which excludes things like CVS/svn repository meta files, backup files and compiled files. – Doug Harris – 2010-02-10T21:40:51.173@doug the command line I posted only copies .class files and directories, nothing else whatsoever, as was specified in his original. But for a less picky backup, -C is definitely helpful. – Justin Smith – 2010-02-10T22:08:43.710