Announcement

Collapse
No announcement yet.

Automatic folder sync across machines?

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Automatic folder sync across machines?

    I've had Kubuntu on my desktop for a few months now, but I'm planning to install it on my new netbook (as soon as the damn thing ships). I'd really like to be able to automatically sync my most-used document folders across both machines -- ideally it would be wireless and in the background, but a USB stick that I plug into one and then the other would work too, I suppose. I would greatly appreciate suggestions for a utility that could manage this without too much headache.

    #2
    Re: Automatic folder sync across machines?

    Ubuntu one could be a sollution for you, there is a kde frontend being that can be found here.

    Comment


      #3
      Re: Automatic folder sync across machines?

      You can also use CLI tool rsync (which is in my opinion the best tool for the job), it can sync directories over network (via ssh) on different hosts. You could create a sync script that you can run manually (sync now), or scheduled via cron.

      If you like GUI way of doing things, there are a few GUI front-ends for rsync, luckybackup is one (and available from the repos).

      Comment


        #4
        Re: Automatic folder sync across machines?

        You can also try Dropbox.

        Comment


          #5
          Re: Automatic folder sync across machines?

          Check out this thread.

          Comment


            #6
            Re: Automatic folder sync across machines?

            Originally posted by arist
            Check out this thread.
            That is certainly an option, but setting up NFS just to sync some directories seems a bit overkill, as rsync can do the syncing (fast) without the need to worry about NFS shares/mounting etc., even over the internet (securely via ssh). Rsync was also written for this particular task, so it's more versatile/optimized than cp when syncing directories.

            Of course, if one wants network shares for other things as well (media/file server etc.), setting up NFS is a good idea (I'd still do any syncing with rsync).

            Comment


              #7
              Re: Automatic folder sync across machines?

              Any way to get rsynch to preserve ownership and permissions and file date/times and only update new or newer files?

              I tried it for a while (admittedly short) and went back to cp because rsynch insisted on stamping all files with the current date/time and messing with ownership and copying everything over every time. I really didn't want to spend hours and hours reading and understanding the rsynch documentation (it seemed to me that the writer assumed that I didn't really need the documentation, but that is probably just me being my usual dense self ) and experimenting with options and path specs to get things just right. The cp options were just so much easier to fathom. In under 15 minutes I had a cp script working, copying the proper files and preserving ownership and date/time stamps.

              Comment


                #8
                Re: Automatic folder sync across machines?

                Originally posted by geezer
                Any way to get rsynch to preserve ownership and permissions and file date/times and only update new or newer files?

                I tried it for a while (admittedly short) and went back to cp because rsynch insisted on stamping all files with the current date/time and messing with ownership and copying everything over every time. I really didn't want to spend hours and hours reading and understanding the rsynch documentation (it seemed to me that the writer assumed that I didn't really need the documentation, but that is probably just me being my usual dense self ) and experimenting with options and path specs to get things just right. The cp options were just so much easier to fathom. In under 15 minutes I had a cp script working, copying the proper files and preserving ownership and date/time stamps.
                You use the archive flag (-a) with rsync it will do what you are asking for. You can also set all the same flags that -a implies (-rlptgoD) individually to achieve the same result.

                Quick edit. Hoping that it might do some people some good. Here is the script that I wrote to do daily snapshots on my home directory (as well as my wife's and my music server). I've been running it about 6 months (since I got my NAS) and it works great.

                Code:
                #!/bin/bash                    
                # Derived from [url]http://www.mikerubel.org/computers/rsync_snapshots/[/url]
                
                unset PATH
                
                # Command Locations
                ECHO=/bin/echo   
                RM=/bin/rm     
                MV=/bin/mv     
                CP=/bin/cp     
                TOUCH=/bin/touch  
                MOUNT=/bin/mount  
                GREP=/bin/grep   
                WC=/usr/bin/wc   
                RSYNC=/usr/bin/rsync
                DATE=/bin/date   
                
                # File Locations
                SNAPSHOT_DIR=/media/backup
                SNAPSHOT_MAX=7      
                SNAPSHOT_FILE=snapshot  
                BACKUP_DIR=/home/tnorris 
                RSYNC_DEST=tnorris@192.168.1.6::tnorrisbackup
                EXCLUDES=/home/tnorris/.exclude       
                PASSWORD_FILE=/home/tnorris/.rsync_pw    
                
                log_info () {
                 $ECHO "`$DATE` - $1"
                }           
                
                log_error () {
                 $ECHO "`$DATE` - $1" >&2
                }             
                
                log_info "Starting snapshot"
                
                # Check if BACKUP_DIR is mounted
                if [ `$MOUNT | $GREP "$SNAPSHOT_DIR" | $WC -l` -eq 0 ]; then          
                 log_error "Exiting. Snapshot Directory is not mounted."            
                 exit                                     
                fi                                       
                                                        
                # Delete the oldest snapshot, if it exists:                   
                if [ -d $SNAPSHOT_DIR/$SNAPSHOT_FILE.$(($SNAPSHOT_MAX-1)) ]; then        
                 $RM -rf $SNAPSHOT_DIR/$SNAPSHOT_FILE.$(($SNAPSHOT_MAX-1))           
                 status=$?                                   
                 if [ $status -eq 0 ]                             
                 then                                     
                  log_info "Removed $SNAPSHOT_DIR/$SNAPSHOT_FILE.$(($SNAPSHOT_MAX-1))"    
                 else                                     
                  log_error "Removal of $SNAPSHOT_DIR/$SNAPSHOT_FILE.$(($SNAPSHOT_MAX-1)) failed."                                      
                  exit $status                                
                 fi                                      
                fi                                       
                
                # Shift each snapshot back one
                for ((i=($SNAPSHOT_MAX-2); i>=0; i--))
                do                  
                 FROM=$i
                 TO=$(($i+1))
                 if [ -d $SNAPSHOT_DIR/$SNAPSHOT_FILE.$FROM ]; then
                  $MV $SNAPSHOT_DIR/$SNAPSHOT_FILE.$FROM $SNAPSHOT_DIR/$SNAPSHOT_FILE.$TO
                  status=$?
                  if [ $status -eq 0 ]
                  then
                   log_info "Moved $SNAPSHOT_DIR/$SNAPSHOT_FILE.$FROM to $SNAPSHOT_DIR/$SNAPSHOT_FILE.$TO"
                  else
                   log_error "Move of $SNAPSHOT_DIR/$SNAPSHOT_FILE.$FROM to $SNAPSHOT_DIR/$SNAPSHOT_FILE.$TO failed."
                   exit $status
                  fi
                 fi
                done
                
                # rsync from the $BACKUP_DIR into the most recent snapshot
                $RSYNC -a --stats --delete --delete-excluded --exclude-from="$EXCLUDES" --link-dest=../$SNAPSHOT_FILE.1 --password-file="$PASSWORD_FILE" "$BACKUP_DIR/" "$RSYNC_DEST"/$SNAPSHOT_FILE.0
                status=$?
                if [ $status -eq 0 ]
                then
                 log_info "Rsynced $BACKUP_DIR/ to $RSYNC_DEST/$SNAPSHOT_FILE.0 linked to ../$SNAPSHOT_FILE.1"
                else
                 log_error "Rsync of $BACKUP_DIR/ to $RSYNC_DEST/$SNAPSHOT_FILE.0 linked to ../$SNAPSHOT_FILE.1 failed."
                 exit $status
                fi
                
                
                # Update the mtime of $SNAPSHOT_FILE.0 to reflect the snapshot time
                $TOUCH $SNAPSHOT_DIR/$SNAPSHOT_FILE.0
                status=$?
                if [ $status -eq 0 ]
                then
                 log_info "Touched $SNAPSHOT_DIR/$SNAPSHOT_FILE.0"
                else
                 log_error "Touch of $SNAPSHOT_DIR/$SNAPSHOT_FILE.0 failed."
                 exit $status
                fi
                
                log_info "Snapshot Complete"

                Comment


                  #9
                  Re: Automatic folder sync across machines?

                  Originally posted by geezer
                  Any way to get rsynch to preserve ownership and permissions and file date/times and only update new or newer files?
                  In addition to what tnorris posted, the -u | --update option can be useful if you are syncing directories

                  from "man rsync":
                  -u, --update
                  This forces rsync to skip any files which exist on the destination and have a modified time that is newer than the source file. (If an existing destination file has a modification time equal to the source file's, it will be updated if the sizes are different.)

                  Note that this does not affect the copying of symlinks or other special files. Also, a difference of file format between the sender and receiver is always considered to be important enough for an update, no matter what date is on the objects. In other words, if the source has a directory where the destination has a file, the transfer would occur regardless of the timestamps.

                  This option is a transfer rule, not an exclude, so it doesn't affect the data that goes into the file-lists, and thus it doesn't affect deletions. It just limits the files that the receiver requests to be transferred.

                  Comment

                  Working...
                  X