crontab - Cron job to SFTP files in a directory -


scenario: need create cron job scans through directory , sftps each file machine

  • bash script : /home/user/sendfiles.sh
  • cron interval : 1 minute
  • directory: /home/user/myfiles
  • sftp destination: 10.10.10.123

create cron job

crontab -u user 1 * * * /home/user/sendfiles.sh 

create script

#!/bin/bash /usr/bin/scp -r user@10.10.10.123:/home/user/myfiles . #remove files after have been sent rm -rf *  

problem: not sure if cron tab correct or how sftp entire directory cron tab

if going executed on cronjob, i'm assuming in order sync dir.

in case, use rdiff-backup make incremental backup. way, things change transferred.

this system use ssh transferring data, using rdiff-backup instead of plain scp. major benefit of doing way speed; faster transfer parts have changed.

this command copy on ssh using rdiff-backup:

rdiff-backup /some/local-dir hostname.net::/whatever/remote-dir 

add cronjob, making sure user executes rdiff backup has ssh keys, not require password.

(about ssh keys: read ssh keys here: http://www.linuxproblem.org/art_9.html once set, try regular ssh see if can log without password.)

something this:

* * * * * rdiff-backup /some/local-dir hostname.net::/whatever/remote-dir 

will copy every minute. (your example, 1 * * * * execute every first minute of each hour; is, once every hour, instead of once every minute)

keep in mind can cause problems if transfer huge hasn't finished transfer. guess want transfers of not huge files. or network speed large. otherwise, change transfer every 5 minutes using */5 * * * * instead.

and finally, read more rdiff-backup here : http://www.nongnu.org/rdiff-backup/examples.html


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -