Difference between revisions of "Sync laptop desktop"

From ArchWiki
Jump to: navigation, search
m (Unison)
(Syncthing is a viable and compatible solution)
 
(9 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}}
 +
It is not always possible to copy one computer's drive to the other. For example, some files must differ on both machines, or respective updates do not match.
  
== Keeping laptop in sync ==
+
==Unison==
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 ==
+
[http://www.cis.upenn.edu/~bcpierce/unison/ Unison].
=== Unison ===
+
[http://caml.inria.fr/about/successes-images/unison.jpg Screenshot].
URL: [http://www.cis.upenn.edu/~bcpierce/unison/ Unison]
+
  
http://caml.inria.fr/about/successes-images/unison.jpg
+
You need to have ssh on both machines, and (the same version of) 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.
  
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.
+
'''~/.unison/electra.prf''' (laptop)
 
+
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.
+
 
+
I use the following scripts:
+
 
+
'''~/.unison/electra.prf''' (My laptop)
+
 
  root = /home/hugo
 
  root = /home/hugo
  root = ssh://pyros//home/hugo
+
  <nowiki>root = ssh://pyros//home/hugo</nowiki>
 
  follow = Path school
 
  follow = Path school
 
  include common
 
  include common
  
'''~/.unison/pyros.prf''' (My desktop)
+
'''~/.unison/pyros.prf''' (desktop)
 
  root = /home/hugo
 
  root = /home/hugo
  root = ssh://electra//home/hugo
+
  <nowiki>root = ssh://electra//home/hugo</nowiki>
 
  follow = Path school
 
  follow = Path school
 
  include common
 
  include common
Line 86: Line 84:
 
  ignore = Path .openoffice2/.lock
 
  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.
+
As you can see, there are two different profiles, one for running from  
 +
the laptop, and one for running the desktop. Files are posted  
 +
here as example, they are nowhere essential for your configuration.
 +
 
 +
Bash aliases were created for quick usage. One example is:
  
I made bash aliases for quick usage. One example is:
 
 
  alias unisync="unison-gtk2 electra -contactquietly -logfile /dev/null"
 
  alias unisync="unison-gtk2 electra -contactquietly -logfile /dev/null"
Meaning I startup unisync using profile 'electra', for when I am on my laptop.
 
  
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:
+
This starts unisync using profile 'electra', for when running the
 +
laptop.
 +
 
 +
A line in ~/Desktop/autostart automates the process when wanting to sync desktop with laptop:
 +
 
 
  xterm -e 'ping -q -W 2 -c 2 pyros &&
 
  xterm -e 'ping -q -W 2 -c 2 pyros &&
 
  unison-gtk2 electra -contactquietly -logfile /dev/null &&
 
  unison-gtk2 electra -contactquietly -logfile /dev/null &&
Line 98: Line 102:
 
  ssh pyros sudo halt' &
 
  ssh pyros sudo halt' &
  
==== Caveats ====
+
=== Limitations ===
- 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.
+
 
 +
You can also use this tool with NFS shares, but you may find that it 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.
 +
 
 +
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 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
 +
 
 +
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.
  
- 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
+
== rsync ==
  
- 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"
+
See [[rsync]]
  
=== rsync ===
+
== rdiff-backup ==
[[rsync]]
+
  
=== rdiff-backup ===
+
The following tool was used with the following backup script:
I used to use this tool with the following backup script:
+
  
 
  #!/bin/sh
 
  #!/bin/sh
Line 161: Line 179:
 
  #umount /boot
 
  #umount /boot
 
  umount /mnt/win
 
  umount /mnt/win
 +
 +
==Syncthing==
 +
See [[syncthing]]

Latest revision as of 16:14, 29 August 2015

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#)

It is not always possible to copy one computer's drive to the other. For example, some files must differ on both machines, or respective updates do not match.

Unison

Unison. Screenshot.

You need to have ssh on both machines, and (the same version of) 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.

~/.unison/electra.prf (laptop)

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

~/.unison/pyros.prf (desktop)

root = /home/hugo
root = ssh://electra//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
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, there are two different profiles, one for running from the laptop, and one for running the desktop. Files are posted here as example, they are nowhere essential for your configuration.

Bash aliases were created for quick usage. One example is:

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

This starts unisync using profile 'electra', for when running the laptop.

A line in ~/Desktop/autostart automates the process when wanting to sync desktop with laptop:

xterm -e 'ping -q -W 2 -c 2 pyros &&
unison-gtk2 electra -contactquietly -logfile /dev/null &&
gxmessage -buttons no:0,yes:1  Syncing done. Shutdown pyros? ||
ssh pyros sudo halt' &

Limitations

You can also use this tool with NFS shares, but you may find that it 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.

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 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

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

rdiff-backup

The following tool was used with the following backup script:

#!/bin/sh

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

Syncthing

See syncthing