Script questions
How do I write a script that create a backup folder that contains all the files that have been updated after a specific date.
In the days of DOS/Windows I did it in a batch file like this: ..... echo off set day=3-22-05 set disk=D: mkdir update_from_%day% cd update_from_%day% mkdir Fib cd Fib xcopy %disk%\Fib\*.* /d:%day% /s cd .. mkdir FibStr# cd FibStr# cd .. Echo DONE! ..... This batch would read the subdirectories and only update those that had newer dates. With a similar file structure, how do I do this in Linux? |
A more simple way would be to do something like:
Code:
cp -Rudfpb --backup=numbered [sourcedir] [targetdir] |
cp -Rudfpb --backup=numbered [sourcedir] [targetdir]
Thanks, but the problem with this method is that it will not do the same thing. This method will end up copying all the files, not just the updated ones, that's the point of specifying a date in the DOS batch file. I would then have to manually delete the files that are numbered, which beside being a time waster would quickly fill up my hard drive. The data base I am using this for is about 20 GB. Copying files for no reason is not cost/space/time effective. What I wrote works great in DOS. I just want an equivalent batch file for linux. |
Well, if you don't want old versions to be kept, the command becomes:
Code:
cp -Rudfp [sourcedir] [targetdir] Code:
find [targetdir] -atime +14 -exec rm {} \; Code:
find [targetdir] -name *.~?~ -atime +14 -exec rm {} \; |
I guess I'm not making myself clear.
Targetdir should be empty to begin with (ideally it should be created by the batch file). Only files that are newer than the specified date should be copied into targetdir. There will be no "old versions" of the files anywhere on the harddisk, either before or after the batch is run. I want to be able to copy only the files that have been modified after a certain date, while preserving their file directory locations. What you have given me is a way to synch up two versions of series of files. That's a different problem. |
cp Doesn't support copying files according to their modification times, so the you will still have to do it with find command.
Code:
$day="`date +%d%m%y`" --Edit-- Here $day is set to the current day. Change it if you like. |
There is also a --after-date=DATE option for 'tar' that you could use to produce a tarball of new files, instead of copying files to a directory.
|
All times are GMT -5. The time now is 06:51 PM. |