.\" Text automatically generated by txt2man
.TH profile-sync-daemon  "22 September 2020" "" ""
.SH NAME
\fBprofile-sync-daemon \fP- Symlinks and syncs browser profiles to RAM (tmpfs) thus reducing HDD/SSD calls and speeding up browsers.
\fB
.SH DESCRIPTION
Profile-sync-daemon (psd) is a tiny pseudo-daemon designed to manage browser profile/profiles 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/profiles. Additionally, psd features several crash-recovery features.
.PP
Design goals of psd:
.RS
.IP \(bu 3
Completely transparent user experience.
.IP \(bu 3
Reduced wear to physical discs (particularly SSDs).
.IP \(bu 3
Speed.
.RE
.PP
Since the profile/profiles, browser cache*, etc. are relocated into tmpfs (RAM disk), the corresponding I/O associated with using the browser is also redirected from the physical disc to the RAM, thus reducing wear to the physical disc and improving browser responsiveness.
.PP
*Note that some browsers such as Chrome/Chromium, Firefox (since v21), Midori, and Rekonq actually keep their cache directories separate from their browser profile directory. It is not within the scope of profile-sync-daemon to modify this behavior; users wishing to relocate this directory, may refer to the following url for several work-arounds: https://wiki.archlinux.org/index.php/Chromium_Tips_and_Tweaks#Cache_in_tmpfs
.SH SETUP
$XDG_CONFIG_HOME/psd/psd.conf (referred to hereafter as "the config file") contains all user managed settings.
.PP
NOTE: edits made to the config file while psd is active will be applied only after the service has been restarted.
.RS
.IP \(bu 3
Optionally enable the use of overlayfs to improve sync speed and to use a smaller memory footprint. Do this in the USE_OVERLAYFS variable. The user will require no password sudo rights to /usr/bin/psd-overlay-helper to use this option and the kernel must support overlayfs version 22 or higher. See the FAQ below for additional details.
.IP \(bu 3
Optionally have psd resync to the filesystem prior to a sleep call. This can help in the event that the system does not properly wake up. Do this in the USE_SUSPSYNC variable.
.IP \(bu 3
Optionally define which browsers are to be managed in the BROWSERS array. If none are defined, the default is all detected browsers.
.IP \(bu 3
Optionally disable the use of crash-recovery snapshots (not recommended). Do this in the USE_BACKUPS variable.
.IP \(bu 3
Optionally define the number of crash-recovery snapshots to keep. Do this in the BACKUP_LIMIT variable.
.RE
.PP
NOTE: occasionally, updates/changes are made to the default config file (/usr/share/psd/psd.conf) upstream. The user copy ($XDG_CONFIG_HOME/psd/psd.conf) will need to be diffed against it.
.SH RUNNING PSD
.SS PREVIEW MODE
The preview option can be called to show users exactly what psd will do/is doing based on the entries in the config file. It will also provide useful information such as profile size, paths, and if any recovery snapshots have been created.
.PP
.nf
.fam C
 $ psd p

 Profile-sync-daemon v6.39

 systemd service: active
 resync-timer:    active
 sync on sleep:   enabled
 use overlayfs:   enabled

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

.nf
.fam C
  browser/psname:  chromium/chromium
  owner/group id:  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-20200423_171359 (92M)
   dir path/size:  /home/facade/.config/chromium-backup-crashrecovery-20200424_112204 (93M)

  browser/psname:  firefox/firefox
  owner/group id:  facade/100
  sync target:     /home/facade/.mozilla/firefox/f8cv8bfu.default
  tmpfs dir:       /run/user/1000/facade-firefox-f8cv8bfu.default

  profile size:    145M
  overlayfs size:  13M
  recovery dirs:   none

.fam T
.fi
.SS START AND STOP PSD
Psd ships with a systemd user service to start or stop it (psd.service). Additionally, a provided resync-timer will run an hourly resync from tmpfs back to the disk. The resync-timer is started automatically with psd.service so there is no need to start the timer; only start psd.service.
.PP
.nf
.fam C
 $ systemctl --user [option] psd.service

.fam T
.fi
Available options:
start
stop
enable
disable
.SS CLEAN MODE
The clean mode will delete ALL recovery snapshots that have accumulated. Only run it when sure these are no longer needed.
.PP
.nf
.fam C
 $ psd c

 Profile-sync-daemon v6.39

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

.fam T
.fi
.SH SUPPORTED BROWSERS
.IP \(bu 3
Chromium (stable, beta, and dev)
.IP \(bu 3
Conkeror
.IP \(bu 3
Epiphany
.IP \(bu 3
Falkon
.IP \(bu 3
Firefox (stable, beta, and aurora)
.IP \(bu 3
Firefox-trunk (this is an Ubuntu-only browser: http://www.webupd8.org/2011/05/install-firefox-nightly-from-ubuntu-ppa.html)
.IP \(bu 3
Google Chrome (stable, beta, and dev)
.IP \(bu 3
Heftig's version of Aurora (Arch Linux: https://bbs.archlinux.org/viewtopic.php?id=117157)
.IP \(bu 3
Icecat
.IP \(bu 3
Iceweasel
.IP \(bu 3
Inox (https://bbs.archlinux.org/viewtopic.php?id=198763)
.IP \(bu 3
Luakit
.IP \(bu 3
Midori
.IP \(bu 3
Opera (legacy, stable, next, and developer)
.IP \(bu 3
Otter-browser
.IP \(bu 3
Palemoon
.IP \(bu 3
QupZilla
.IP \(bu 3
Qutebrowser
.IP \(bu 3
Rekonq
.IP \(bu 3
Seamonkey
.IP \(bu 3
Vivaldi
.IP \(bu 3
Vivaldi-snapshot
.RE
.PP
Psd's infrastructure can work in principal with any browser that uses a generic chrome or mozilla, etc. format. User supplied profiles are provided in /usr/share/psd/contrib/ and can be manually copied to /usr/share/psd/browsers/ if one wishes to sync that particular browser. Make a corresponding entry in the BROWSERS array within the config file. Support for these is unsupported.
.SH NOTE ON SYMLINKED PROFILES
Currently, psd does not support symlinked profiles and will refuse to sync if one is detected. For example, your firefox profile is ~/.mozilla/firefox/f8cv8bfu.default but you have moved that directory to /foo/bar/f8cv8bfu.default and replaced it with symlink:
.PP
.nf
.fam C
 $ ls -l ~/.mozilla/firefox
 lrwxrwxrwx 1 facade users  26 Oct  1 17:02 f8cv8bfu.default -> /foo/bar/f8cv8bfu.default

.fam T
.fi
Running psd in preview mode will end in an error informing you of this:
.PP
.nf
.fam C
 $ psd p

 Warning!
 /home/facade/.mozilla/firefox/f8cv8bfu.default appears to be a symlink but these are not supported.
 Please make the browser profile a live directory and try again. Exiting.

.fam T
.fi
A proper work around for firefox is to simply edit ~/.mozilla/firefox/profiles.ini defining the canonical path there. One also needs to adjust the IsRelative flag like so:
.PP
.nf
.fam C
 [Profile0]
 Name=default
 IsRelative=0
 Path=/foo/bar/f8cv8bfu.default

.fam T
.fi
Other solutions may exist for other browsers but documenting them all here is out of scope.
.SH SUPPORTED DISTROS
Since psd is just a bash script with a systemd service, it should run on any flavor of Linux running systemd. Several distros provide an official package or user-maintained option to install psd. One can also build psd from source. See the official website for available packages, dependencies, and installation instructions
.SH FAQ
Q1: What is overlayfs mode?
.PP
A1: Overlayfs is a simple union filesystem mainlined in the Linux kernel version 3.18.0. When used with psd, a reduced memory footprint and faster sync operations can be realized. 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.
.PP
See the example in the PREVIEW MODE section above which shows a system using overlayfs to illustrate the typical memory savings. 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 new data is written to the profile, but in common use cases, the overlayfs size will always be less than the profile size.
.PP
Q2: How do I enable overlayfs mode?
.PP
A2: First, be sure psd is not active or else any changes to the config file will be ignored until it is restarted. Overlayfs mode is enabled with the USE_OVERLAYFS= variable which should be set to "yes" in the config file. Psd will automatically detect the overlayfs version available to the kernel if it is configured to use one of them. It is recommended to run psd in preview mode to verify that the system can in fact use overlayfs.
.PP
Users wanting to use overlayfs mode MUST have sudo rights without password prompt to /usr/bin/psd-overlay-helper or global sudo rights without password prompt. If the user does not have global rights, add the following line to /etc/sudoers after any other lines defining sudo access. It is recommended to use /usr/bin/visudo as root to set this up:
.PP
.nf
.fam C
 foo ALL=(ALL) NOPASSWD: /usr/bin/psd-overlay-helper

.fam T
.fi
Q3: Why do I have another browser profile directory "foo-back-ovfs" when I enable overlayfs?
.PP
A3: The way overlayfs works is to mount a read-only base copy (so-called lower dir) of the profile, and manage the new data on top of that. In order to avoid resyncing to the read-only filesystem, a copy is used instead. So using overlayfs is a trade-off: faster initial sync times and less memory usage vs. disk space in the home dir.
.PP
Q4: I need more memory to accommodate my profile/profiles in /run/user/xxxx. How can I allocate more?
.PP
A4: The standard way of controlling the size of /run/user/ is the RuntimeDirectorySize directive in logind.conf (see the man page for logind.conf for more). By default, 10% of physical memory is used but one can increase it safely. Remember that tmpfs only consumes what is actually used; the number specified here is just a maximum allowed.
.PP
Q5: My system crashed for some reason and psd didn't sync back. What do I do?
.PP
A5: The "last good" backup of the browser profile/profiles should be the filesystem. Upon restarting psd (on a reboot for example), a check is performed to see if the symlink to the tmpfs copy of the 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.
.PP
Q6: Where can I find this snapshot?
.PP
A6: It depends on the browser. The snapshot will be located 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, a chromium snapshot will be ~/.config/chromium-backup-crashrecovery-20130912_153310 -- of course, the date_time suffix will be different.
.PP
Q7: How can I restore the snapshot?
.PP
A7: Follow these steps:
.RS
.IP 1. 4
Stop psd.
.IP 2. 4
Move the "bad" copy of the profile to a backup (don't blindly delete anything).
.IP 3. 4
Copy the snapshot directory to the name that browser expects.
.PP
Example using chromium:
.IP 1. 4
systemctl \fB--user\fP stop psd.service
.IP 2. 4
mv ~/.config/chromium ~/.config/chromium-bad
.IP 3. 4
cp \fB-a\fP ~/.config/chromium-backup-crashrecovery-20130912_153310 ~/.config/chromium
.RE
.PP
At this point, launch chromium which will use the backup snapshot just copied into place. If all is well, it is safe to delete ~/.config/chromium-bad and the snapshot. Remember, to start psd, no browsers must be open (or psd will refuse to start).
.PP
Q8: Can psd delete the snapshots automatically?
.PP
A8: Yes, run psd with the "clean" switch to delete snapshots.
.SH CONTRIBUTE
Users wishing to contribute to this project, should fork it and send a pull request. Source is freely available on github.
.SH BUGS
Discovered a bug? Please open an issue.
.RS
.IP \(bu 3
Several cases of data loss have been reported when using eCryptFS and psd, therefore until this issue is flushed out, users of eCryptFS are encouraged not to use psd unless willing to help troubleshoot suspected browser corruption. See: https://github.com/graysky2/profile-sync-daemon/issues/158
.SH ONLINE
.IP \(bu 3
Project page: https://github.com/graysky2/profile-sync-daemon
.IP \(bu 3
Wiki page: https://wiki.archlinux.org/index.php/Profile-sync-daemon
.SH AUTHOR
graysky (graysky AT archlinux DOT us)
