Difference between revisions of "Sync laptop desktop"

From ArchWiki
Jump to: navigation, search
m (Unison)
(Rewriting)
 
(10 intermediate revisions by 7 users not shown)
Line 1: Line 1:
[[Category:Networking]]
+
[[Category:Internet applications]]
 
[[fr:Synchroniser vos ordinateurs]]
 
[[fr:Synchroniser vos ordinateurs]]
 
{{Expansion}}
 
{{Expansion}}
 +
{{Poor writing|first person}}
  
== Keeping laptop in sync ==
+
This article provides ideas how to keep two systems (folders) in sync across devices. This is a challenging problem, especially if both devices are used concurrently and files may be in conflict.
Ever since I acquired a laptop, I thought about how to keep my laptop up to date with my home computer, and vice versa. You cannot just cp one image to the other, for many reasons. For example, some files simply ''have'' to differ on both machines, and sometimes there are updates on one computer, and updates on the other computer.  
 
  
== Solutions ==
+
==Unison==
=== Unison ===
 
URL: [http://www.cis.upenn.edu/~bcpierce/unison/ Unison]
 
  
http://caml.inria.fr/about/successes-images/unison.jpg
+
[http://www.cis.upenn.edu/~bcpierce/unison/ Unison].
 +
[http://caml.inria.fr/about/successes-images/unison.jpg Screenshot].
  
This is my favorite solution, and I absolutely love it. I have tried a lot of tools, but this one beats them all hand down. It is easy to configure, and yet still secure and flexible.
+
Unision allows you to do a sync in both directions. The great feature of Unison is that it provides you with a GUI that can assist you in resolving conflicts when synchronizing files.
  
You need to have ssh on both machines, and unison installed on both machines (your laptop and desktop). Then with a few simple commands you can synchronise directories, and in a GUI you can select which things you wish to have synchronised and which not. You can also resolve conflicts.
+
===Prerequisites===
 +
You need to have the same version of unison installed on both machines as well as SSH.
  
I use the following scripts:
+
===Configuration example===
  
'''~/.unison/electra.prf''' (My laptop)
+
Consider user Joe that has two systems, Alpha and Beta.
  root = /home/hugo
+
 
  root = ssh://pyros//home/hugo
+
The example below shows you the following useful Unison configuration file instructions:
 +
* Define the two <code>root</code> folders to sync;
 +
* Using the <code>follow</code> instruction to follow symbolic links;
 +
* Including a <code>common</code> set of file ignores.
 +
 
 +
'''~/.unison/alpha.prf'''
 +
  root = /home/joe
 +
  <nowiki>root = ssh://beta//home/joe</nowiki>
 
  follow = Path school
 
  follow = Path school
 
  include common
 
  include common
  
'''~/.unison/pyros.prf''' (My desktop)
+
'''~/.unison/beta.prf'''
  root = /home/hugo
+
  root = /home/joe
  root = ssh://electra//home/hugo
+
  <nowiki>root = ssh://alpha//home/hugo</nowiki>
 
  follow = Path school
 
  follow = Path school
 
  include common
 
  include common
Line 36: Line 43:
 
  ignore = Name .ICEauthority
 
  ignore = Name .ICEauthority
 
  ignore = Name .Xauthority
 
  ignore = Name .Xauthority
ignore = Path {.songinfo,.radinfo}
 
ignore = Path .adesklets
 
ignore = Path .Azureus
 
ignore = Path .forward
 
ignore = Path adesklets
 
ignore = Path .ethereal
 
ignore = Path .sheep
 
ignore = Path .xinitrc
 
ignore = Path .config
 
ignore = Path .xscreensaver
 
ignore = Path .xawtv
 
ignore = Path .radio
 
ignore = Path .forward
 
ignore = Path .dc++
 
ignore = Path .quodlibet
 
ignore = Path .tvtime
 
ignore = Path .config/graveman
 
ignore = Path .xmodmap
 
ignore = Path .java
 
ignore = Path .tvlist*
 
ignore = Path .thumbnails
 
ignore = Path .ssh
 
ignore = Path .viminfo
 
ignore = Path .vim/tmp
 
ignore = Path Desktop
 
ignore = Path .wine*
 
ignore = Path motion
 
ignore = Path src/ufobot/test_pipe
 
ignore = Path tmp
 
ignore = Path local
 
ignore = Path books
 
ignore = Path .mozilla/firefox/*/Cache*
 
ignore = Path .liferea/cache
 
ignore = Path .liferea/mozilla/liferea/Cache
 
ignore = Path .sylpheed-*/*.bak
 
ignore = Path .sylpheed-*/folderlist.xml*
 
ignore = Path .liferea/new_subscription
 
ignore = Path .mozilla/firefox/pluginreg.dat
 
ignore = Path .mozilla/firefox/*/lock
 
ignore = Path .mozilla/firefox/*/XUL.mfasl
 
ignore = Path .mozilla/firefox/*/xpti.dat
 
ignore = Path .mozilla/firefox/*/cookies.txt
 
ignore = Path .xbindkeysrc
 
ignore = Path .unison/ar*
 
ignore = Path .gaim/icons
 
ignore = Path .gaim/blist.xml
 
ignore = Path .asoundrc
 
ignore = Path .maillog
 
ignore = Path .openoffice2/.lock
 
  
As you can see, I have two different profiles, one for when I run from my laptop, and one for when I run from my desktop. I posted my files here as example, they are nowhere essential for your configuration.
+
You can call unison from the command line, for example:
 +
 
 +
alias unisync="unison-gtk2 beta -contactquietly -logfile /dev/null"
 +
 
 +
=== Limitations ===
  
I made bash aliases for quick usage. One example is:
+
You can also use this tool with NFS shares instead of SSH, but you may find that it is
alias unisync="unison-gtk2 electra -contactquietly -logfile /dev/null"
+
slower. The advantage of using SSH is that the local unison asks the remote unison process to check
Meaning I startup unisync using profile 'electra', for when I am on my laptop.
+
for updates, rather than trying to do it locally using NFS (which requires additional network traffic).
  
I also have a line in ~/Desktop/autostart to automate the process for me when I am home and want to sync with my laptop:
+
If you are using a ssh port different from the default (22),
  xterm -e 'ping -q -W 2 -c 2 pyros &&
+
for example 1022, use this line in your prf file:  
unison-gtk2 electra -contactquietly -logfile /dev/null &&
+
  sshargs = -p 1022
gxmessage -buttons no:0,yes:1  Syncing done. Shutdown pyros? ||
 
ssh pyros sudo halt' &
 
  
==== Caveats ====
+
If you are using symbolic links and want to synchronize your files on a
- You can also use this tool with NFS shares, but I found that that is slower, because using the ssh solution it asks the other side to check for updates, and thus not requiring network traffic for that part of the syncing process.
+
vfat system (usb key for example), unison will not accept them and
 +
generate errors. As a solution, you can tell unison not to synchronize links (<code>links</code> option).
 +
However, if this is not an option for you, you can find them on your system with:
 +
find ~/folder -type l
  
- In the case you are using a ssh port different from the default (22), for example 1022, use this line in your prf file: sshargs = -p 1022
+
Unison is very sensitive and requires the '''exact same versions''' on [https://groups.yahoo.com/neo/groups/unison-users/conversations/topics/11439|both client and server]. Also, unison '''must''' be compiled against the same OCaml version on all peers too. Making it highly unfeasible for a heterogeneous network.
  
- If you are using symbolic links and want to synchronise your files on a vfat system (usb key for example), unison will not accept them and generate errors. You cannot just tell unison you do not want symbolic links, you have to name them all. To find them on your system, you can run "find ~/folder -type l"
+
== rsync ==
  
=== rsync ===
+
See [[rsync]].
[[rsync]]
 
  
=== rdiff-backup ===
+
==Syncthing==
I used to use this tool with the following backup script:
+
See [[syncthing]].
  
#!/bin/sh
+
==Other==
+
Consider Dropbox, Owncloud or Nextcloud.
mount /bak
 
#mount /boot
 
mount /mnt/win
 
 
rdiff-backup \
 
    --exclude-regexp 'cache$' \
 
    --exclude-regexp '(?i)/te?mp$' \
 
    --exclude /mnt \
 
    --exclude /vol \
 
    --exclude /bak \
 
    --exclude /usr/media \
 
    --exclude /usr/media/misc \
 
    --exclude /usr/lib \
 
    --exclude /tmp \
 
    --exclude /var/dl \
 
    --exclude /var/spool \
 
    --exclude /var/cache \
 
    --exclude /proc \
 
    --exclude /dev \
 
    --exclude /sys \
 
/ /bak/sys
 
 
echo "----------------------------------------"
 
echo " * Listing increments of backup"
 
echo "----------------------------------------"
 
rdiff-backup --list-increments /bak/sys
 
 
echo ""
 
echo "----------------------------------------"
 
echo " * Removing backups older than 5 Weeks"
 
echo "----------------------------------------"
 
rdiff-backup --force --remove-older-than 5W /bak/sys
 
 
##Force is necessary because:
 
#Fatal Error: Found 2 relevant increments, dated:
 
#Sat Apr 10 12:39:24 2004
 
#Sat Apr 17 04:15:01 2004
 
#If you want to delete multiple increments in this way, use the --force.
 
 
echo ""
 
echo "----------------------------------------"
 
echo " * Disk usage after backup"
 
echo "----------------------------------------"
 
df -h
 
 
umount /bak
 
#umount /boot
 
umount /mnt/win
 

Latest revision as of 22:09, 11 March 2017

Tango-view-fullscreen.pngThis article or section needs expansion.Tango-view-fullscreen.png

Reason: please use the first argument of the template to provide a brief explanation. (Discuss in Talk:Sync laptop desktop#)

Tango-edit-clear.pngThis article or section needs language, wiki syntax or style improvements.Tango-edit-clear.png

Reason: first person (Discuss in Talk:Sync laptop desktop#)

This article provides ideas how to keep two systems (folders) in sync across devices. This is a challenging problem, especially if both devices are used concurrently and files may be in conflict.

Unison

Unison. Screenshot.

Unision allows you to do a sync in both directions. The great feature of Unison is that it provides you with a GUI that can assist you in resolving conflicts when synchronizing files.

Prerequisites

You need to have the same version of unison installed on both machines as well as SSH.

Configuration example

Consider user Joe that has two systems, Alpha and Beta.

The example below shows you the following useful Unison configuration file instructions:

  • Define the two root folders to sync;
  • Using the follow instruction to follow symbolic links;
  • Including a common set of file ignores.

~/.unison/alpha.prf

root = /home/joe
root = ssh://beta//home/joe
follow = Path school
include common

~/.unison/beta.prf

root = /home/joe
root = ssh://alpha//home/hugo
follow = Path school
include common

~/.unison/common

ignore = Regex .*(cache|Cache|te?mp|history|thumbnails).*
ignore = Name sylpheed.log*
ignore = Name unison.log
ignore = Name .ICEauthority
ignore = Name .Xauthority

You can call unison from the command line, for example:

alias unisync="unison-gtk2 beta -contactquietly -logfile /dev/null"

Limitations

You can also use this tool with NFS shares instead of SSH, but you may find that it is slower. The advantage of using SSH is that the local unison asks the remote unison process to check for updates, rather than trying to do it locally using NFS (which requires additional network traffic).

If you are using a ssh port different from the default (22), for example 1022, use this line in your prf file:

sshargs = -p 1022

If you are using symbolic links and want to synchronize your files on a vfat system (usb key for example), unison will not accept them and generate errors. As a solution, you can tell unison not to synchronize links (links option). However, if this is not an option for you, you can find them on your system with:

find ~/folder -type l

Unison is very sensitive and requires the exact same versions on client and server. Also, unison must be compiled against the same OCaml version on all peers too. Making it highly unfeasible for a heterogeneous network.

rsync

See rsync.

Syncthing

See syncthing.

Other

Consider Dropbox, Owncloud or Nextcloud.