7

What is the simplest way to unidirectional incremental syncing of a folder present on a Linux system.

+1 for using the command line. +2 for not using rsync (Seems to have some problems on my system.)

3
  • 3
    What exactly are your problems with rsync?
    – innaM
    Jul 17, 2009 at 9:51
  • 5
    Since rsync very likely is the simplest answer, explain what problems you're having with that. (The problems may spill over to any other solution, anyhow.)
    – Telemachus
    Jul 17, 2009 at 10:37
  • Necro, yes, but: sshfs may also work for anyone looking at this question.
    – IronEagle
    Apr 18, 2019 at 19:15

4 Answers 4

6

csync is a file synchronizer especially designed for you, the normal user.

csync is a library and ships commandline client by default. It is server-less and allows synchronisation through either sftp or samba.

Usage examples:

csync /home/csync smb://csync:[email protected]/Users/csync
csync /home/csync sftp://[email protected]:2222/home/csync
2
  • The csync command is provided by the csync-owncloud ubuntu package. (sudo apt-get install csync-owncloud libcsync-plugin-sftp libcsync-plugin-smb if you want them as well) Jul 21, 2015 at 20:08
  • So this runs a one-time synchronization on demand. I haven't found any information on how to use this for monitoring and continually synchronizing a directory. Jul 21, 2015 at 20:10
8

I think you should solve your problems with rsync, that is the tried and true" syncronization tool for unixes.

rsync -uav --delete /loal/path example.com:/remote/path

Note: For bidirectional sync, you can use unison as well as csync.

1
  • +1, but this was only a partial answer for me. If you need to use rsync over ssh, use rsync -uav --delete -e ssh remoteuser@remotehost:/remote/dir /this/dir/
    – zelanix
    Jul 14, 2014 at 14:44
2

This is how I would do a unidirectional sync with bare tools.

At the onset, tar the entire set of files and copy them to the destination point.
Also, setup a marker in the base directory.

touch /Source/base/directory/last-sync-time.txt

Now, we want to keep sync'ing from Source to Destination.

At the next time slot for syncing forward (from Source to Destination),

# The backup script
cd /Source/base/directory
tar cfj -N ./last-sync-time.txt backup.tar.bz2 .
scp backup.tar.bz2 user@backup-server:/Backup/Directory/
touch /Source/base/directory/last-sync-time.txt
rm -f backup.tar.bz2
  1. The -N ./filename tells tar to archive only files modified or created after filename was modified/created.
    • Using a local reference for time confirms you make no mistake; if a backup was not taken for some reason, the next one will accumulate it
    • You can setup this script as a cronjob entry on the Source machine
    • I am assuming you will use scp with public key authentication
    • Also assuming you can reach the backup-server whenever this script is issued.
    • To be safer, you can add checks for confirming backup was stored and then, issue the touch command
    • You can choose to also insert commands to expand the backups overlaying them over previous ones at the Destination point; Or, keep incremental tar.bz2 archives.
1

I Use this short script for monitoring and continually synchronizing a directory with remote sftp folder;

#!/bin/sh
dir1=/home/user/folder
 while inotifywait -qqre modify "$dir1";
 do
    csync /home/user/folder sftp://remoteuser:remotepass@remoteaddress:remoteport/remotefolderpath
done

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .