LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   SCP files from one server to another (https://www.linuxquestions.org/questions/linux-newbie-8/scp-files-from-one-server-to-another-670621/)

rev1976 09-17-2008 03:26 PM

SCP files from one server to another
 
Hi all,

I need to scp files (DB2 backup files) from one server (A) to another server (B) and I would like to automate this. What i need to do is to find the files older than 11 days and scp those files to the other server. And then i need to delete the files on server (A) that were sent over. Any help would be greatly appreciated. So far i have the this command:

find /data/db2inst1/backup -name "*.0.db2inst1.NODE0000.CATN0000.*" -mtime +11 -type f -exec scp {} <server(B)>:<server(B) directory> \; -print

So this will find the files 11 days or older and scp them over to server (B). Please let me know if this is correct or if there's another way to do it. Thank you.

TB0ne 09-17-2008 03:36 PM

Quote:

Originally Posted by rev1976 (Post 3283558)
Hi all,

I need to scp files (DB2 backup files) from one server (A) to another server (B) and I would like to automate this. What i need to do is to find the files older than 11 days and scp those files to the other server. And then i need to delete the files on server (A) that were sent over. Any help would be greatly appreciated. So far i have the this command:

find /data/db2inst1/backup -name "*.0.db2inst1.NODE0000.CATN0000.*" -mtime +11 -type f -exec scp {} <server(B)>:<server(B) directory> \; -print

So this will find the files 11 days or older and scp them over to server (B). Please let me know if this is correct or if there's another way to do it. Thank you.

I can't test it right now, but it looks good to me.

However, anytime file deletions are automated, I get nervous. Since I've been snakebit by this before ("What? You deleted them? Yeah, I know I said you could, but I really need it NOW!"), I'd probably do a move on the file to another drive/partition, where they could sit unnoticed. If someone complained or needed one, I'd have it quickly available. If not, I'd probably go out there every now and then, and nuke things older than a month or so....

chrism01 09-17-2008 07:45 PM

Actually, if he's got a copy on another server I wouldn't worry too much. I would gzip or bzip2 the files unless they are being actively used. Saves on disk space.
I'd also tend to do it in a loop rather than as a one-liner, as you can then add other cmds easily eg email conf list of which files got copied, or email error msg if failure...
This sounds like its going to end up as a cron job.

TB0ne 09-18-2008 08:13 AM

Quote:

Originally Posted by chrism01 (Post 3283792)
Actually, if he's got a copy on another server I wouldn't worry too much. I would gzip or bzip2 the files unless they are being actively used. Saves on disk space.

Agreed on the compression, but I *ALWAYS* worry about deleting a file. I've had them get corrupted, or have some goober delete them from the backup location. If I have the space, I make more copies. :)

chrism01 09-18-2008 08:21 PM

In the long run offline backups are de-rigeur, pref off-site.
:)


All times are GMT -5. The time now is 07:01 PM.