]> BookStack Code Mirror - website/blob - content/docs/admin/backup-restore.md
Update filesystem-permissions.md
[website] / content / docs / admin / backup-restore.md
1 +++
2 title = "Backup and Restore"
3 description = "How to back up and restore your BookStack data"
4 date = "2017-01-01"
5 type = "admin-doc"
6 +++
7
8 While BookStack does not currently have a built-in way to backup and restore content,
9 it can usually be done via the command line with relative ease.
10
11 Please note the below commands are based on using Ubuntu. If you are using a
12 different operating system you may have to alter these commands to suit.
13
14 ---
15
16 ### Backup
17
18 There are two types of content you need to backup: Files and database records.
19
20 #### Database
21
22 The easiest way to backup the database is via `mysqldump`:
23
24 ```bash
25 # Syntax
26 ## Only specify the `-p` option if the user provided has a password
27 mysqldump -u {mysql_user} -p {database_name} > {output_file_name}
28
29
30 # Example
31 mysqldump -u benny bookstack > bookstack.backup.sql
32 ```
33
34 If you are using MySQL on Ubuntu, and are using the `root` MySQL
35 user, you will likely have to run the command above with `sudo`:
36
37 ```bash
38 sudo mysqldump -u root bookstack > bookstack.backup.sql
39 ```
40
41 The resulting file (`bookstack.backup.sql` in the examples above) will contain
42 all the data from the database you specified. Copy this file to somewhere safe,
43 ideally on a different device.
44
45 #### Files
46
47 Below is a list of files and folders containing data you should back up. The paths
48 are shown relative to the root BookStack folder.
49
50 * `.env` - File, contains important configuration information.
51 * `public/uploads` - Folder, contains any uploaded images.
52 * `storage/uploads` - Folder, contains uploaded page attachments.
53 * `themes/` - Folder, contains any configured [visual/logical themes](/docs/admin/hacking-bookstack/#visual-theme-system).
54
55 Alternatively you could backup up your whole BookStack folder but only the above
56 contain important instance-specific data by default.
57
58 The following command will create a compressed archive of the above folders and
59 files:
60
61 ```bash
62 tar -czvf bookstack-files-backup.tar.gz .env public/uploads storage/uploads
63 ```
64
65 The resulting file (`bookstack-files-backup.tar.gz`) will contain all your file
66 data. Copy this to a safe place, ideally on a different device.
67
68 ---
69
70 ### Restore
71
72 If you are restoring from scratch follow the [installation](/docs/admin/installation)
73 instructions first to get a new BookStack instance set-up but
74 **do not run the `php artisan migrate` installation step when installing BookStack**.
75 You may need to comment this command out if using an installer script.
76
77 If you are using a docker-container-based set-up, restore the database before running the BookStack container.
78 An example of the process using a linuxserver.io-based docker-compose setup can be seen [in our video here](https://youtu.be/6A8hLuQTkKQ?t=1050).
79
80 #### Database
81
82 To restore the database you simply need to execute the sql in the output file from the `mysqldump`
83 you performed above. To do this copy your database SQL backup file onto the
84 BookStack or database host machine and run the following:
85
86 ```bash
87 # Syntax
88 mysql -u {mysql_user} -p {database_name} < {backup_file_name}
89 ## Only specify the -p if the user provided has a password
90
91 # Example
92 mysql -u benny -p bookstack < bookstack.backup.sql
93
94 # If using the root user on Ubuntu you may
95 # have to run the above with root permissions via sudo:
96 sudo mysql -u root bookstack < bookstack.backup.sql
97 ```
98
99 If you are restoring to a new version of BookStack you will have to run
100 `php artisan migrate` after restore to perform any required updates to the database.
101
102 #### Files
103
104 To restore the files you simply need to copy them from the backup archive
105 back to their original locations.  If you created a compressed `bookstack-files-backup.tar.gz`
106 archive as per the backup instructions above you can simply copy that file to
107 your BookStack folder then run the following command:
108
109 ```bash
110 tar -xvzf bookstack-files-backup.tar.gz
111 ```
112
113 If you get errors during the above command it may be due to permissions.
114 Change permissions so you can write to the restore locations.
115
116 After a backup of the files you should reset the permissions to ensure any write-required
117 locations are writable by the server. The locations required for this can be
118 found in the [installation instructions](/docs/admin/installation).
119
120 #### Configuration (.env File)
121
122 During a restore, you may end up merging various configuration options between your 
123 old and new instance `.env` files, to get things working for the new environment.
124 For example, it's common to use the old `.env` settings for most things but use database
125 settings from the `.env` file of a newly created instance. 
126
127 One thing to be aware of is that you should use the `APP_KEY` value of the old `.env` file since
128 this is used for various features like the encryption of multi-factor authentication credentials.
129 Changing the `APP_KEY` may cause such features to break.
130
131 #### URL Changes
132
133 If you are restoring into an environment where BookStack will run on a different URL,
134 there are a couple of things you'll need to do after restoring everything:
135
136 - Within the `.env` config file update the `APP_URL` value to exactly match your new base URL.
137 - Run the ["Update System URL" command](/docs/admin/commands/#update-system-url) to update your database content to use your new URL.
138
139 If you migrated web-server configuration files, you may also need to tweak those to correctly use the new URL.