| 1 | = Trac Backup |
| 2 | |
| 3 | [[TracGuideToc]] |
| 4 | |
| 5 | Trac backups are a copied snapshot of the entire [TracEnvironment project environment] directory, including the database. Backups can be created using the `hotcopy` command of [TracAdmin trac-admin]. |
| 6 | |
| 7 | '''Note''': Trac uses the `hotcopy` nomenclature to match that of [http://subversion.tigris.org/ Subversion], to make it easier to remember when managing both Trac and Subversion servers. |
| 8 | |
| 9 | == Creating a Backup |
| 10 | |
| 11 | Create a backup of a live TracEnvironment by running: |
| 12 | {{{#!sh |
| 13 | $ trac-admin /path/to/projenv hotcopy /path/to/backupdir |
| 14 | }}} |
| 15 | |
| 16 | The database will be locked while hotcopy is running. |
| 17 | |
| 18 | The resulting backup directory is safe to handle using standard file-based backup tools like `tar` or `dump`/`restore`. |
| 19 | |
| 20 | Please note, the `hotcopy` command will not overwrite a target directory. When the target exists the operation will end with an error: `Command failed: [Errno 17] File exists:` This is discussed in [trac:#3198 #3198]. |
| 21 | |
| 22 | == Restoring a Backup |
| 23 | |
| 24 | To restore an environment from a backup, stop the process running Trac, ie the web server or [TracStandalone tracd], restore the contents of your backup to your [TracEnvironment project environment] directory and restart the process. |
| 25 | |
| 26 | If you are using a database other than SQLite, you'll need to restore the database from the dump file. The dump file is saved in the environment `db` directory. |
| 27 | |
| 28 | To restore a PostgreSQL database backup, use the command: |
| 29 | {{{#!sh |
| 30 | $ psql -U <user> -d <database> -f /path/to/postgresql.dump |
| 31 | }}} |
| 32 | |
| 33 | The `<database>` option is the same as the [TracEnvironment#DatabaseConnectionStrings database connection string] in the [TracIni#trac-database-option "[trac] database"] option of //trac.ini//. |
| 34 | |
| 35 | Similarly, for MySQL: |
| 36 | |
| 37 | {{{#!sh |
| 38 | $ mysql -u <user> -p <database> < /path/to/mysql.dump |
| 39 | }}} |
| 40 | |
| 41 | ---- |
| 42 | See also: TracAdmin, TracEnvironment, [trac:TracMigrate TracMigrate] |