Difference between revisions of "Profile-sync-daemon"

From ArchWiki
Jump to: navigation, search
m (updated conf path for version 6.03)
(Running psd to manage profiles: rewording / grammar fix)
Line 145: Line 145:
 
With the release of version 6.00 of psd, the only init system that is officially supported is systemd. Psd ships with a service users must use to start or stop it. Additionally, a provided timer file will run the an hourly resync from tmpfs back to the disk. The timer is started automatically with psd.service.
 
With the release of version 6.00 of psd, the only init system that is officially supported is systemd. Psd ships with a service users must use to start or stop it. Additionally, a provided timer file will run the an hourly resync from tmpfs back to the disk. The timer is started automatically with psd.service.
  
For users unfamiliar with system'd user mode, example innovation:
+
For users unfamiliar with systemd user mode, use the following commands to enable the psd service:
  
 
  systemctl --user start psd.service
 
  systemctl --user start psd.service

Revision as of 22:30, 8 September 2015

Profile-sync-daemonAUR (psd) is a tiny pseudo-daemon designed to manage browser profile(s) in tmpfs and to periodically sync back to the physical disc (HDD/SSD). This is accomplished by an innovative use of rsync to maintain synchronization between a tmpfs copy and media-bound backup of the browser profile(s). Additionally, psd features several crash recovery features.

Benefits of psd

Running this daemon is beneficial for two reasons:

  1. Reduced wear to physical drives
  2. Speed

Since the profile(s), browser cache*, etc. are relocated into tmpfs (RAM disk), the corresponding onslaught of I/O associated with using the browser is also redirected from the physical drive to RAM, thus reducing wear to the physical drive and also greatly improving browser speed and responsiveness. For example, the access time of RAM is on the order of nanoseconds while the access time of physical discs is on the order of milliseconds. This is a difference of six orders of magnitude or 1,000,000 times faster.

Note: Some browsers such as Chrome/Chromium, Firefox (since v21), Midori, and Rekonq actually keeps their cache directories separately from their profile directory. It is not within the scope of profile-sync-daemon to modify this behavior; users are encouraged to refer to the Chromium tweaks#Cache in tmpfs section for Chromium and to the Firefox Ramdisk article for several workarounds. An easy fix is to move the various browsers' cache directory from their default location (e.g. /home/$USER/.cache/<browser>/<profile>/) to the corresponding profile directory, e.g. /home/$USER/.mozilla/firefox/<profile>/cache, and then symlink the new cache folder back to its original location. This way, profile-sync-daemon will automatically take into account the cache folder too.

Setup and installation

Warning: With the release of v6.00 of psd, a global config and a system service has been deprecated. The wiki article has been modified to reflect these changes. Alternative init systems are no longer supported with this release of psd.

Install the profile-sync-daemonAUR package.

Edit the config file

Run psd the first time which will create $XDG_CONFIG_HOME/psd/psd.conf which contains all settings.

Note: Any edits made to this file while psd is active will be applied only after psd has been restarted from the systemd user service.
  • Optionally enable the use of overlayfs to improve sync speed even further and use a smaller memory footprint. Note that this option requires your kernel be configured to use either the 'overlay' (Arch default) or 'overlayfs' (Ubuntu <15.05) kernel module. See the FAQ below for additional details on this feature.
  • Optionally uncomment and define which browsers are to be managed in the BROWSERS array. Note that the default is all browsers unless otherwise defined.
  • Optionally define the location of your distro's tmpfs which is only used as a fall-back option should systemd not correctly set $XDG_RUNTIME_DIR for you (/run/user/$UID). Do this in the VOLATILE variable.
  • Optionally disable the use of crash-recovery snapshots. Do this in the USE_BACKUPS variable.

Example: Let us say that Chromium, Opera and Midori are installed but only Chromium and Opera are to be sync'ed to tmpfs since the user keeps Midori as a backup browser and it is seldom used:

# List browsers separated by spaces to include in the sync. Useful if you do not
# wish to have all possible browser profiles sync'ed.
#
# Possible values:
#  chromium
#  chromium-dev
#  conkeror.mozdev.org
#  epiphany
#  firefox
#  firefox-trunk
#  google-chrome
#  google-chrome-beta
#  google-chrome-unstable
#  heftig-aurora
#  icecat
#  luakit
#  midori
#  opera
#  opera-developer
#  opera-beta
#  qupzilla
#  palemoon
#  rekonq
#  seamonkey
#  vivaldi
#
# If the following is commented out (default), then all available/supported 
# browsers will be sync'ed, separated by comma
BROWSERS="chromium opera"

Beginning with version 5.54 of psd, native support for overlayfs is included. Uncomment the USE_OVERLAYFS="yes" line to enable it rather than the default full copy to reduce the memory costs and to improve sync/unsync operations.

Note: This feature requires a Linux kernel version of 3.18.0 or greater to work.

Supported browsers

Currently, the following browsers are auto-detected and managed:

Using psd

Preview (parse) mode

The 'parse' option can be called to show users exactly what psd will do/is doing based on $XDG_CONFIG_HOME/psd/psd.conf as well printout useful information such as profile size, paths, and if any recovery snapshots have been created.

$ profile-sync-daemon parse
Profile-sync-daemon v6.03 on Arch Linux.

 Systemd service is currently active.
 Systemd resync service is currently active.
 Overlayfs v23 is currently active.

Psd will manage the following per /home/facade/.psd/psd.conf settings:

 browser/psname:  chromium/chromium
 owner/group:     facade/100
 sync target:     /home/facade/.config/chromium
 tmpfs dir:       /run/user/1000/facade-chromium
 profile size:    93M
 overlayfs size:  39M
 recovery dirs:   2 <- delete with the c option
  dir path/size:  /home/facade/.config/chromium-backup-crashrecovery-20150117_171359 (92M)
  dir path/size:  /home/facade/.config/chromium-backup-crashrecovery-20150119_112204 (93M)

 browser/psname:  firefox/firefox
 owner/group:     facade/100
 sync target:     /mnt/data/docs/facade/mozilla/firefox/f8cv8bfu.default
 tmpfs dir:       /run/user/1000/facade-firefox-f8cv8bfu.default
 profile size:    145M
 overlayfs size:  13M
 recovery dirs:   none

As shown in the output and as stated above, if no specific browser or subset of browsers are defined in the BROWSERS array, psd will sync ALL supported profiles that it finds for the given user(s).

Clean mode

The clean mode will delete ALL recovery snapshots that have accumulated. Run this only if you are sure that you want to delete them.

$ psd c

Profile-sync-daemon v6.03 on Arch Linux.

Deleting 2 crashrecovery dirs for profile /home/facade/.config/chromium
 /home/facade/.config/chromium-backup-crashrecovery-20150117_171359
 /home/facade/.config/chromium-backup-crashrecovery-20150119_112204

Running psd to manage profiles

With the release of version 6.00 of psd, the only init system that is officially supported is systemd. Psd ships with a service users must use to start or stop it. Additionally, a provided timer file will run the an hourly resync from tmpfs back to the disk. The timer is started automatically with psd.service.

For users unfamiliar with systemd user mode, use the following commands to enable the psd service:

systemctl --user start psd.service
systemctl --user enable psd.service

Sync at more frequent intervals (optional)

The package provided re-sync timer triggers once per hour. Users may optionally redefine this behavior simply by extending the systemd unit. The example below changes the timer to sync once every ten minutes:

~/.config/systemd/user/psd-resync.timer.d/frequency.conf
--------------------------------------------------------
[Unit]
Description=Timer for Profile-sync-daemon
PartOf=psd.service

[Timer]
OnUnitActiveSec=10m

See man systemd.timer for additional options.

Caveats for Firefox and Heftig's Aurora ONLY

The way psd keeps track of browser profiles and sync targets requires users to have a unique name as the last directory for all profiles in their respective $HOME/.mozilla/browser/profiles.ini files. psd will check when it is called to run for this and refuse if this rule is not satisfied. The following is an example of a BAD profile that will fail the the test. Note that although each full path is unique, they both end in the same name! Again, the user must modify the profiles.ini and the corresponding directory on the filesystem to correct this in order to use psd.

~/.mozilla/firefox/profiles.ini
[General]
StartWithLastProfile=1

[Profile0 for user facade]
Name=normal
IsRelative=0
Path=/mnt/data/docs/facade/mozilla/firefox/myprofile.abc
Default=1

[Profile1 for user debbie]
Name=proxy
IsRelative=0
Path=/mnt/data/docs/debbie/mozilla/firefox/myprofile.abc

FAQ

What is overlayfs and why do I want to use it?

Overlayfs is a simple union file-system mainlined in the Linux kernel version 3.18.0. Starting with psd version 5.54, overlayfs can be used to reduce the memory footprint of psd's tmpfs space and to speed up sync and unsync operations. The magic is in how the overlay mount only writes out data that has changed rather than the entire profile. The same recovery features psd uses in its default mode are also active when running in overlayfs mode. Overlayfs mode is enabled by uncommenting the USE_OVERLAYFS="yes" line in $XDG_CONFIG_HOME/psd/psd.conf followed by a restart of the daemon.

There are several versions of overlayfs available to the Linux kernel in production in various distros. Versions 22 and lower have a module called 'overlayfs' while newer versions (23 and higher) have a module called 'overlay' -- note the lack of the 'fs' in the newer version. Psd will automatically detect the overlayfs available to your kernel if it is configured to use one of them.

Tango-inaccurate.pngThe factual accuracy of this article or section is disputed.Tango-inaccurate.png

Reason: Security issue (Discuss in Talk:Profile-sync-daemon#Version 6)

Since version 6.0 of psd, users wanting to user this mode MUST have sudo rights to /usr/bin/mount and /usr/bin/umount. The following line in /etc/sudoers will supply your user with these rights. Add it using /usr/bin/visudo as root:

foo ALL=NOPASSWD: /usr/bin/mount,/usr/bin/umount

See the example in the PREVIEW MODE section above which shows a system using overlayfs to illustrate the memory savings that can be achieved. Note the "overlayfs size" report compared to the total "profile size" report for each profile. Be aware that these numbers will change depending on just how much data is written to the profile, but in common use cases, the overlayfs size will always be less than the profile size.

How do I load the overlay or the overlayfs module?

Simply call /usr/bin/modprobe to load the module (as root) will load it. Again, try 'overlay' first, but if modprobe is unable to locate that module, try 'overlayfs' as a fallback. Note that using modprobe to load the module will NOT reload the module on the next boot. The recommended method to have the needed module load automatically at boot is to place it in /etc/modules-load.d/load_me.conf (the file should contain a single word consisting of just the module name).

My system crashed and did not sync back. What do I do?

Odds are the "last good" backup of your browser profiles is just fine still sitting happily on your filesystem. Upon restarting psd (on a reboot for example), a check is preformed to see if the symlink to the tmpfs copy of your profile is invalid. If it is invalid, psd will snapshot the "last good" backup before it rotates it back into place. This is more for a sanity check that psd did no harm and that any data loss was a function of something else.

Note: Users can disable the snapshot/backup feature entirely by uncommenting and setting the USE_BACKUPS variable to 'no' in $XDG_CONFIG_HOME/psd/psd.conf if desired.

Where can I find this snapshot?

It depends on the browser. You will find the snapshot in the same directory as the browser profile and it will contain a date-time-stamp that corresponds to the time at which the recovery took place. For example, chromium will be ~/.config/chromium-backup-crashrecovery-20130912_153310 -- of course, the date_time suffix will be different for you.

How can I restore the snapshot?

  • Stop psd.
  • Confirm that there is no symlink to the tmpfs browser profile directory. If there is, psd did not stop correctly for other reasons.
  • Move the "bad" copy of the profile to a backup (do not blindly delete anything).
  • Copy the snapshot directory to the name that browser expects.

Example using Chromium:

mv ~/.config/chromium ~/.config/chromium-bad
cp -a ~/.config/chromium-backup-crashrecovery-20130912_153310 ~/.config/chromium

At this point you can launch chromium which will use the backup snapshot you just copied into place. If all is well, close the browser and restart psd. You may safely delete ~/.config/chromium-backup-crashrecovery-20130912_153310 at this point.

Can psd delete the snapshots automatically?

Yes, run psd with the "clean" switch to delete snapshots.

Support

Post in the discussion thread with comments or concerns.

PSD on other distros

psd is a bash script and should therefore run on any Linux distro. Around 1 dozen distros provide an official package or user-maintained option to install psd. See the official website for available packages and installation instructions.

See also