LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Copy latest files from linux to network drive (https://www.linuxquestions.org/questions/linux-newbie-8/copy-latest-files-from-linux-to-network-drive-4175485965/)

evang 11-26-2013 04:06 PM

Copy latest files from linux to network drive
 
I have a linux server running an accounting package, I would like copy any files from that data directory that were altered each day to a network drive so it can be included in our backups.

Currently I am manually doing this each day by copy/paste between the directories. As I will be away from the business over christmas I need an icon staff can click on as they leave the office each day to run a script to do this.

I have extremely basic knowledge of any linux commands and my attempts to build a suitable script have so far failed completely.

The data drive path is: /u/pp/data

The target directory is svr-sbs1210/data/finance/share linux/copy/data

Any help would be fantastic, due to the size of the information I'd prefer to only copy file that changed the day the script is run rather than copy all files every day if possible.

allend 11-26-2013 04:27 PM

I suggest using rsync run as a cron job. e.g. http://www.marksanborn.net/howto/use...nthly-backups/

timl 11-26-2013 04:29 PM

How's about...

Quote:

rsync -r -a -v -t /u/pp/data svr-sbs1210/data/finance/share linux/copy/data
rsync copies only files which have changed.

Quote:

-r recursive
-a archive mode (bascially, preserve all settings associated with the file on the original box)
-v verbose
-t the doco about this switch is limited. My take is that this means rsync preserves the date of the original file.
I have added my understanding of the switches. If anyone can improve on this pls do.

Test out the rsync command any time. Then you need to do a bit of digging regarding crontab to schedule the job to run every night - no need for manual intervention.
Quote:

0 1 * * * /home/tim/cron/backup-docs
that is a job I run every day at 1am to backup my docs.

HTH

sag47 11-26-2013 04:39 PM

Quote:

Originally Posted by timl (Post 5071056)
Code:

rsync -r -a -v -t /u/pp/data svr-sbs1210/data/finance/share linux/copy/data

Your options are redundant and can be shortened. The -a option covers -r and -t already. So if you truly wanted the -v option then your command can be shortened to -a -v. Also, -a -v is the same as saying -av so in my opinion your command should look something like this.

Code:

rsync -av /u/pp/data svr-sbs1210/data/finance/share linux/copy/data
Though really since it's a cron job there's no need to see output if it is successful so -v is even unnecessary in my opinion.

In any case, I agree rsync is a good solution for the original poster.

SAM

unSpawn 11-26-2013 04:42 PM

Quote:

Originally Posted by timl (Post 5071056)
I have added my understanding of the switches. If anyone can improve on this pls do.

Nothing to improve except the man page says "-a" means "-rlptgoD".


Quote:

Test out the rsync command any time.
A good way could be to use "--dry-run --verbose --itemize-changes --stats" for testing (lots of output) and when running as a cron job add "--quiet --log-file=/var/log/rsync.log" to save output for review if necessary.

schneidz 11-26-2013 05:20 PM

i see there is a space in the directory name so it probably needs to be quoted (or escaped):
rsync -av /u/pp/data "svr-sbs1210/data/finance/share linux/copy/data"
- or -
rsync -av /u/pp/data svr-sbs1210/data/finance/share\ linux/copy/data

also if this goes in cron then it will need to know the full path of where the svr-sbs1210 subdirectory is located.


All times are GMT -5. The time now is 10:38 AM.