.\" Man page generated from reStructuredText. . . .nr rst2man-indent-level 0 . .de1 rstReportMargin \\$1 \\n[an-margin] level \\n[rst2man-indent-level] level margin: \\n[rst2man-indent\\n[rst2man-indent-level]] - \\n[rst2man-indent0] \\n[rst2man-indent1] \\n[rst2man-indent2] .. .de1 INDENT .\" .rstReportMargin pre: . RS \\$1 . nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin] . nr rst2man-indent-level +1 .\" .rstReportMargin post: .. .de UNINDENT . RE .\" indent \\n[an-margin] .\" old: \\n[rst2man-indent\\n[rst2man-indent-level]] .nr rst2man-indent-level -1 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]] .in \\n[rst2man-indent\\n[rst2man-indent-level]]u .. .TH "FSSYNC" 1 "" "" .SH NAME fssync \- File system synchronization tool (1-way, over SSH) .SH SYNOPSIS .sp \fBfssync\fP \fB\-d\fP \fIdb\fP \fB\-r\fP \fIroot\fP [\fIoption\fP\&...] \fIhost\fP .SH DESCRIPTION .sp fssync is a 1\-way file\-synchronization tool that tracks inodes and maintains a local database of files that are on the remote side, making it able to: .INDENT 0.0 .IP \(bu 2 handle efficiently a huge number of dirs/files .IP \(bu 2 detect renames/moves and hard\-links .UNINDENT .sp It aims at minimizing network traffic and synchronizing every detail of a file system: .INDENT 0.0 .IP \(bu 2 all types of inode: file, dir, block/character/fifo, socket, symlink .IP \(bu 2 preserve hard links .IP \(bu 2 modification time, ownership/permission/ACL, extended attributes .IP \(bu 2 sparse files .UNINDENT .sp Other features: .INDENT 0.0 .IP \(bu 2 it can be configured to exclude files from synchronization .IP \(bu 2 fssync can be interrupted and resumed at any time, making it tolerant to random failures (e.g. network error) .IP \(bu 2 algorithm to synchronize file content is designed to handle big files like VM images efficiently, by updating fixed\-size modified blocks in\-place .UNINDENT .sp Main usage of fssync is to prevent data loss in case of hardware failure, where RAID1 is not possible (e.g. in laptops). .sp On \fI\%Btrfs\fP [1] file systems, fssync is an useful alternative to \fIbtrfs send\fP (and \fIreceive\fP) commands, thanks to filtering capabilities. This can be combined with Btrfs snapshotting at destination side for a full backup solution. .SH USAGE .sp Use \fBfssync \-\-help\fP to get the complete list of options. .sp The most important thing to remember is that the local database must match exactly what\(aqs on the destination host: .INDENT 0.0 .IP \(bu 2 Files that are copied on the destination host must not be modified. And nothing should be manually created inside destination directories. If you still want to access data on remote host, you should do it through a read\-only bind mounts (requires Linux >= 2.6.26). .IP \(bu 2 You must have 1 database per destination, if you plan to have several copies of the same source directory. .UNINDENT .sp Look at \fB\-c\fP option if you wonder whether your database matches the destination directory. .sp First run of fssync: .INDENT 0.0 .IP \(bu 2 The easiest way is to let fssync do everything. Specify a non\-existing file path to \fB\-d\fP option and a empty or non\-existing destination directory (see \fB\-R\fP option). fssync will automatically creates the database and copy all dirs/files to remote host. .IP \(bu 2 A faster way may be to do the initial copy by other means, like a raw copy of a partition. If you\(aqre absolutely sure the source and destination are exactly the same, you can initialize the database by specifying \fB\-\fP as host. If inode numbers are the same on both sides, which is the case if data were copied at block level, you can modify the source partition while you are initializing the DB on the destination one, and get back the DB locally. .UNINDENT .sp An example of wrapper around fssync, with a filter, can be found at \fIexamples/fssync_home\fP .sp fssync does never descend directories on other filesystems. Inodes masked by mount points are also skipped, so they should be unmounted temporarily if you want them to be synchronized. The same result can be achieved by synchronizing from a bind mount. .sp See also the \fI\%NONE cipher switching\fP [3] patch if you don\(aqt need encryption and you want to speed up your SSH connection. .SH HOW IT WORKS .sp fssync maintains a single SQLite table of all dirs/files that are on the remote side. Each row matches a path, with its inode (on local side), other metadata (on remote side) and a \fIchecked\fP flag. .sp When running, fssync iterates recursively through all local dirs/files and for each path that is not ignored (see \fB\-f\fP option), it queries the DB to decide what to do. If already \fIchecked\fP, path is skipped immediately. When a path is synchronized, it is marked as \fIchecked\fP\&. At the end, all rows that are not \fIchecked\fP corresponds to paths that don\(aqt exist anymore. Once they are deleted on the remote side, all \fIchecked\fP flags are reset. .SS Failure tolerance .sp In fact, fssync doesn\(aqt require that the database matches perfectly the destination. It tolerates some differences in order to recover any interrupted synchronization caused by a network failure, a file operation error, or anything other than an operating system crash of the local host (or something similar like a power failure). .sp In most cases, this is done by the remote host, which automatically create (or overwrite) an inode of the expected type if necessary. The only exception is that the remote will never delete a non\-empty directory on its own. For most complex cases, fssync journalizes the operation in the database: in case of failure, fssync will be able to recover on next sync. .SS Race conditions .sp A race condition means that other processes on the local host are modifying inodes that fssync is synchronizing. fssync handles any kind of race condition. In fact, fssync has nothing to do for most cases. .sp When a race condition happens, fssync does not guarantee that the remote data is in a consistent state. Each sync always fixes existing inconsistencies but may introduces others, so fssync is not suitable for hot backuping of databases. .sp With Btrfs, you can get consistency by snapshotting at source side. .SH SIMILAR PROJECTS .sp The idea of maintaining a local database actually comes from \fI\%csync2\fP [4]\&. I was about to adopt it when I realized that I really needed a tool that always detects renames/moves of big files. That\(aqs why I see fssync as a partial rewrite of csync2, with inode tracking and without bidirectional synchronization. The local database really makes fssync & csync2 faster than the well\-known \fI\%rsync\fP [5]\&. .SH SEE ALSO .sp \fBsqlite3\fP(1), \fBssh\fP(1) .SH BUGS/LIMITATIONS/TODO .INDENT 0.0 .IP 1. 3 For performance reasons, the SQLite database is never flushed to disk while fssync is running. Which means that if the operating system crashes, the DB might become corrupted, and even if it isn\(aqt, it may not reflect anymore the status of the remote host and later runs may fail (for example, fssync refuses to replace a non\-empty folder it doesn\(aqt know by a non\-folder). So in any case, it is advised to rebuild the DB. .sp If the DB is not corrupted and you don\(aqt want to rebuild it, you can try to update it by running fssync again as soon as possible, so that the same changes are replayed. fssync should be able to detect that all remote operations are already performed. See also \fB\-c\fP and \fB\-F\fP options. .IP 2. 3 fssync should not trash the page cache by using \fBposix_fadvise\fP(2). Unfortunately, Linux does not implement \fBPOSIX_FADV_NOREUSE\fP yet (see \fI\%https://lkml.org/lkml/2011/6/24/136\fP for more information). We could do like \fI\%Bup\fP [2], which uses information returned by \fBmincore\fP(2) in order to \fI\%eject pages after save more selectively\fP [6]\&. .IP 3. 3 fssync process on remote side might leave parent directories with wrong permissions or modification times if it is terminated during specific operation like recovery (at the very beginning), cleanup (at the end), rename (if a directory is moved). That is, all operations that need to temporarily alter a directory that is not being checked. \(dqWontfix\(dq for now, because it is unlikely to happen and any solution would be quite heavy, for little benefit. .IP 4. 3 What is not synchronized: .INDENT 3.0 .IP \(bu 2 access & change times: I won\(aqt implement it. .IP \(bu 2 inode flags (see \fBchattr\fP(1) and \fBlsattr\fP(1)): some flags like \fIC\fP or \fIc\fP are important on Btrfs so this could be a nice improvement, at least if it was implemented partially. .IP \(bu 2 file\-system specific properties ? .UNINDENT .IP 5. 3 Don\(aqt rely on permissions settings to prevent access to inodes on destination side. This is because metadata are synchronized after data (in the case of a directory, it means all inodes under this directory is synchronized before its metadata) and in some cases, an attacker could access to sensitive data while fssync is running. Access should be denied on a parent directory of your destination tree (or at the root of this tree if you\(aqre careful enough to keep it secure on source side). .UNINDENT .SH NOTES .IP [1] 5 \fI\%https://btrfs.wiki.kernel.org/\fP .IP [2] 5 \fI\%https://github.com/bup/bup\fP .IP [3] 5 \fI\%https://github.com/rapier1/openssh\-portable\fP .IP [4] 5 \fI\%http://oss.linbit.com/csync2/\fP .IP [5] 5 \fI\%http://rsync.samba.org/\fP .IP [6] 5 \fI\%https://github.com/bup/bup/commit/b062252a5bca9b64d7b3034b6fd181424641f61e\fP .SH AUTHOR Julien Muchembled .\" Generated by docutils manpage writer. .