Recipes: sync, check and back up¶
Commands that work with uFTP. The ones marked tried are run by the uFTP tests (test/test_site_commands.py) against a real server with lftp 4.9.2 and curl; the others are not tried here.
What uFTP gives a client for this¶
| You want | uFTP has |
|---|---|
| Keep the date of a file when you upload it | MFMT (announced in FEAT): lftp, and rclone according to its documentation, use it |
| Know if a file changed without downloading it | XSHA256, XSHA1, XMD5, XCRC and HASH (see Commands) |
| Move only the files that changed | the date and size (MDTM, SIZE, MFMT) |
| Start a backup or a dump on the server | SITE RUN (see Run scripts) |
lftp (tried)¶
# upload a folder, only what is newer; the dates are kept (MFMT), so the second run has nothing to do
lftp -u alice -e "mirror -R --only-newer --verbose /home/me/site /site; bye" ftp://host
# download a folder, only what is newer
lftp -u alice -e "mirror --only-newer /site /home/me/site-copy; bye" ftp://host
# the checksum of a file on the server, without downloading it (SHA-256, the same as sha256sum)
lftp -u alice -e "quote XSHA256 big.iso; bye" ftp://host # 250 <64 hex digits>
sha256sum big.iso
# with TLS (FTPS), as usual: set ftp:ssl-force yes; set ssl:verify-certificate yes
A backup made on the server (tried)¶
The user needs the permission run and you list the script (see Run scripts). With the script uftp-backup-folder of the repository (contrib/site-commands/):
quote SITE RUN backup photos # 250 Job 7 started: backup
quote SITE STATUS 7 # running for 12 s ... then: finished, exit 0, ... output uftp-job-7.out
get uftp-job-7.out -o photos-backup.tar.gz
(typed in lftp, or as lftp -u alice -e "quote SITE RUN backup photos; bye" ftp://host). SITE STATUS 7 says running until the job ends: ask again (the control connection has an idle limit, so the reply to SITE RUN is at once).
In a shell script, to wait for the end:
job=$(lftp -u alice -e "quote SITE RUN backup photos; bye" ftp://host | sed -n 's/^250 Job \([0-9]*\) started.*/\1/p')
until lftp -u alice -e "quote SITE STATUS $job; bye" ftp://host | grep -q 'finished\|timeout\|ended by signal'; do sleep 5; done
A database dump (mysqldump, pg_dump)¶
contrib/site-commands/uftp-dump-mysql and uftp-dump-postgres take the name of one database as the parameter and write the compressed dump on standard output (the job file you download). The credentials stay in a file that only the user of uFTP can read, never in uftpd.cfg or on a command line.
They are tried with stand-in programs, not with a real database server: try one with your database before you rely on it.
SITE_COMMAND_dump = /usr/local/sbin/uftp-dump-mysql
PERMISSIONS_0 = list,download,run
Then quote SITE RUN dump shop and get uftp-job-<id>.out.
curl (tried)¶
curl -T backup.tar.gz ftp://alice:PASSWORD@host/backup.tar.gz # upload
curl -O ftp://alice:PASSWORD@host/backup.tar.gz # download
# FTPS: curl --ssl-reqd ... ; a password on a command line is visible to the other users of the machine: use ~/.netrc (curl -n)
rclone (not tried here)¶
rclone has an FTP backend (rclone config, type ftp). According to its documentation it sets the modification time with MFMT when the server announces it, which uFTP does; it does not use the checksum commands, so rclone sync compares size and date. Try it with your data first.
Good to know¶
- A checksum command reads the whole file in a thread of its own, up to
HASH_MAX_SIZE_MB(256 by default); a bigger file is answered552. lftpandrclonesend the date they read from the local file: the clocks do not need to agree,MFMTsets the date as given (UTC).- Several clients can run at the same time: a checksum or a job of one does not make the others wait.