Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
This would copy all the files from [sourcedir] to [targetdir]. If a file by the same name already exists in [targetdir], it will get backed up with prefix ~1~, ~2~, ~3~, and so on. The newest file will always have the same name in [targetdir] as in [sourcedir]. Only files that have been changed from the versions in [targetdir] will get copied.
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]
Like I said, only the files that differ from the ones currently in [targetdir] will get copied, i.e. not all the files. That's what u switch in the command is for. See man cp for more detailed information. I use find command to expire the files in [targetdir] if they are older than 14 days, i.e. the files will get refreshed (or removed if they no loger exist in [sourcedir]) every two weeks and the maximum age for backup files is two weeks:
This of course causes the files that have been in the backup for more than two weeks to be re-copied also, so it might not be what you want. To expire only backups, use something like:
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.