LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Auto Sync (https://www.linuxquestions.org/questions/linux-newbie-8/auto-sync-4175499773/)

AmirSI 03-28-2014 04:33 AM

Auto Sync
 
Hello,
on my Ubuntu server i have mounted folder from NAS-QNAP and one from SFTP.

NAS-QNAP folder in automounted in /etc/fstab using:

//10.0.0.0/vmware-bkp/Git-Server/ /home/administrator/mnt/QNAP-Git-Server/ cifs username=admin,password=admin 0 0

And for SFTP folder i added command in /etc/rc.local :

sshfs enerdat@backup.com:/backup ~/mnt/test/

I tryed to add SFTP also in /etc/fstab, but nothing didnt work.

Now i need this two folders to auto sync everyday at 2am.
I tryed to run basic command whit rsync, but for now nothing is working.

lleb 03-28-2014 06:54 AM

well sounds like you are on the right track with rsync, but we need more info. if you are unsuccessful at mounting the sftp share via fstab what else have you tried? have you looked into autofs? also keep in mind that if you can manually mount the sftp share you dont need to have it mounted for rsync to work as rsync will run over ssh connection just as sftp share does.

use code flags, post the exact output errors and the code you are using to attempt to get your rsync to run. also this is a job for cron.

AmirSI 03-28-2014 07:11 AM

Ok, i will take a look at autofs. I finally made rsync to start working, i added some additional properties.

Now it look like this:

rsync -pvzhriu --delete /home/administrator/mnt/QNAP-Git-Server/ /media/server/Git-Server/

Now i need some typ of schedule to run this command, ever day at 2am.
If possible as super user,

AmirSI 03-28-2014 07:34 AM

Will it work, if i just add this line in "/etc/crontab".

00 03 * * * root rsync -pvzhriu --delete /home/administrator/mnt/QNAP-Git-Server/ /media/server/Git-Server/

If anyone have any better way to do this sync, please let me know...

lleb 03-29-2014 11:59 AM

always best to put it into a simple little script, put your path in your crontab, and run it from cron. see my first post.

you might also want to consider building in error checking and logging so that data can be verified it was transmitted and you can use the logging down the road if something happens for trouble shooting.

AmirSI 03-31-2014 02:26 AM

I had problem over the weekend, its looks like that over some time, i lose connection to sftp.
So when schedule try to run my command, it just create new folders, becuse sftp is not mounted.
How can i mount this sftp, to stay connected?

If i add "-o reconnect", will this do the work:
sshfs user@backup.si:/backup /media/server/ -o reconnect

lleb 03-31-2014 07:11 AM

this is where the script will come in handy. create a bash script that verifies if the share is mounted, if not mount it, then perform the transfer via rsync. confirm the transfer then exit program.


All times are GMT -5. The time now is 05:56 PM.