Skip to content

Backup Agent database

Resilio Agents keep an sqlite database file for each of the Jobs they do. For Distribution and Consolidation Jobs the database files are deleted from disk once the Job run completes while Script Job does not have the database at all. Database files for Synchronization Jobs are kept on disk all the time while the Agent is in the Job.
Agent keeps records of each file that is present in the Job and, which is important, has ever been present in the Job, as well as records about archived, ignored files and their attributes.

If an Agent is removed from the Job, the database file is deleted. Adding the Agent back to the Job means that it will have to build the new database from scratch - index the files on its storage, merge the folder tree with that on other Agents. This is a long lasting process and on millions of files may take up to several days.

That is why it's highly advisable to periodically backup Agents' database for Jobs with 1M+ files, in case of unexpected necessity to re-add the Agent to the Job, so as to have all the indices already built up. This will allow to get the Job back in balance way faster. For example, having a backup of database will help in the following cases:

  • Database error occurred. There might be multiple causes of it. For details, see Database error.
  • System crash or permanent storage device damage. Most likely this will lead to the database corruption.
  • Agent is overwhelmed with load, for example, volume of synchronization tasks to perform it way above hardware capacity. Usually support team engineers may advise to re-add the Agent to the Job after investigation.
  • Human mistake.

How to know which database files to backup

Databases are stored in the Agents' storage folder:
Windows: C:\ProgramData\Resilio\Connect Agent
Mac: /Users/username/Library/Application Support/Resilio Connect Agent
Linux:

  • Installed as an app: ./sync in the current directory, from which you launch the agent.
  • Installed from package as service: /var/lib/resilio-agent or the path where --log argument in process points.
  • Installed from package and running with current user: /home/username/.config/resilio-agent or path where --log argument in process points. See the linked guide for other platforms.

There are two ways to decide what database to backup: * by file size. Each file in the database takes around 2kb (4 KB if synchronization of file permissions is enabled) per each file and subdirectory in the Job. Mind that files which were present in the Job previously also add to the size. Knowing the numbers of files in the Job will help to reveal the necessary database file. * by file name. Database files are named after Job internal identifier. You can find internal identifier in dump debug status for any Agent participating in Job.

Mc Backup Agent Db

Databases with extensions .db, sf.db and files.db are of interest. It's necessary to backup all such files belonging to the Job, i.e. have the same name.

Mc Backup Agent Files

How to backup the database files

Do not perform backup when you see database error for this Agent in a Job!

Unfortunately, the Agents don't have this functionality out of the box and it has to be done manually or be automated with scripts. Basically the procedure boils down to the steps:

  1. Stop the Resilio Agent. At this point you will notice that database shared memory storage and journal files (.shm and .wal respectively) will be removed, no need to backup these.
  2. Copy the database file(s) to a safe place. You can arrange the way to store them as you need. Be sure to group all database files from a single backup somehow so as to be able to restore them back if necessary.
  3. Start the Agent.

Tip

It's advisable to perform backup during off-load hours. There's also no real need to keep more than two backups, three backups to be on a very safe side.

Backing up databases for an active Agent

Since copying active SQLite DBs is not officially supported, do the active Agent backup at your own risk.

If Agent restart takes too long, you can backup databases without shutting the Agent down. Follow the suggestions below:

  • Perform it during off-load hours when the database gets as few changes at the moment as it is possible.
  • Also copy *.shm and *.wal files.
  • Once done, run the integrity check for every .db file backed up using sqlite3 CLI tool: sqlite3 <db_filename> 'pragma integrity_check'
  • If the integrity check fails - backup the database again.

How to restore backup

The procedure is the opposite to the doing backup:

  1. Stop the Agent, this is a compulsory step.
  2. Copy the latest backup - all the backed up database files - to the Agent's storage.
  3. Start the Agent.

It's normal that the Agent might be still missing some of the latest file updates, records of which got lost due to the initial reason why you needed to restore the backup.
Give the Agent some time to load and get the Job in balance with other Agents.