Module upm::backup [] [src]

Support for making backups of database file.

Because tupm is experimental code, we are fairly paranoid about making backups of the database early and often -- perhaps even to the point of annoyance to anyone wondering why their UPM directory is littered with all these files. Backup databases are suffixed with a timestamp and a .bak extension. Backups are made in the following scenarios:

  1. Up to 30 backups of the pre-existing local database are made whenever the database is saved. If 30 backups are already present, the oldest is deleted to make room for a new one.
  2. When a sync operation is about to overwrite a remote database with a new revision, it first uploads a backup file of the new revision. If the upload of this backup file fails, the pre-existing remote database is not deleted and an error is presented to the user. This is particularly useful since syncing a new revision consists of non-atomic steps: a "delete" operation followed by an "upload" operation. If the "delete" succeeds but the "upload" fails, the remote database would be lost forever in the absence of backups. There is currently no limit on the number of backups stored on the remote server.

Functions

backup

If the file at the specified path exists, make a backup, and remove any old backup files as needed to bring the total number of backup files for this path within the limit. Ok(true) is returned on success, otherwise an error is returned.

generate_backup_filename

Generate a backup filename for the specified path by appending a timestamp and .bak extension.