RedmineBackupRestore » History » Revision 11
Revision 10 (stefan pofahl, 2025-01-31 16:33) → Revision 11/14 (stefan pofahl, 2025-01-31 17:22)
h1. Backing up and restoring Redmine
{{>toc}}
h2. Backup
Redmine backups should include:
* Database
* Attachments (stored in the @files@ directory under the installation directory by default)
h3. Backing up database
h4. MySQL
The @mysqldump@ command can be used to backup the contents of your MySQL database to a text file. For example:
<pre>
/usr/bin/mysqldump -u <username> -p<password> -h <hostname> <redmine_database> > /path/to/backup/db/redmine.sql
</pre>
You can find @<username>@, @<password>@, @<hostname>@, and @<redmine_database>@ in the file @config/database.yml@. @<host_name>@ may not be required depending on your installation of the database.
h4. PostgreSQL
The @pg_dump@ command can be used to backup the contents of a PostgreSQL database to a text file. Here is an example:
<pre>
/usr/bin/pg_dump -U <username> -h <hostname> -Fc --file=redmine.sqlc <redmine_database>
</pre>
You can find @<username>@, @<hostname>@, and @<redmine_database>@ in the file @config/database.yml@. @<hostname>@ may not be required depending on your installation of the database. The @pg_dump@ command will prompt you to enter the password when necessary.
h4. SQLite
SQLite databases are all contained in a single file, so you can back them up by copying the file to another location.
You can determine the file name of SQLite database by looking at @config/database.yml@.
h3. Backing up attachments
All file uploads are stored in @attachments_storage_path@ (defaults to the @files/@ directory). You can copy the contents of this directory to another location to easily back it up.
+WARNING:+ @attachments_storage_path@ may point to a different directory other than @files/@. Be sure to check the setting in @$RAILS_ROOT/$RAILS_ROOT/config/configuration.yml@ to avoid making a useless backup.
This file may not exist (status: Redmine v5.0.4), it exist a template @$RAILS_ROOT/config/configuration.yml.example@ to change
the standard values, copy this file and rename it to @$RAILS_ROOT/$RAILS_ROOT/configuration.yml@.
In my installation via Debian package, the attached files are stored in
@/var/lib/redmine/default/files@.
You can find this folder by file search, attach a file to wiki-page or add a document to a project and look for "*_filename.filextention", in my case the stored file start with 12 digits: <@yymmddhhmmss@>.
Interesting is also where the file @Gemfile.lock@ is located, for me it was two levels above in the folder hierarchy: @/var/lib/redmine/files@
Keep also in mind, you may you have plugins installed that my have a different storage location, in my case it is the plugin "DMSF":https://www.redmine.org/plugins/redmine_dmsf.
h3. Sample backup script
Here is a simple shell script that can be used for daily backups (assuming you're using a MySQL database):
<pre>
# Database
/usr/bin/mysqldump -u <username> -p<password> <redmine_database> | gzip > /path/to/backup/db/redmine_`date +%Y-%m-%d`.gz
# Attachments
rsync -a /path/to/redmine/files /path/to/backup/files
</pre>
h2. Restore
h3. Restoring a database
h4. MySQL
For example if you have a gziped dump file with the name @2018-07-30.gz@, then the database can be restored with the following command:
<pre>
gunzip -c 2018-07-30.gz | mysql -u <username> --password <redmine_database>
Enter password:
</pre>
h4. PostgreSQL
When the option @-Fc@ of the command @pg_dump@ is used like it is at the above example then you need to use the command @pg_restore@:
<pre>
pg_restore -U <username> -h <hostname> -d <redmine_database> redmine.sqlc
</pre>
otherwise a text file can be restored with @psql@:
<pre>
psql <redmine_database> < <infile>
</pre>
h4. SQLite
Copy the database file from the backup location.