Backup & Restore
This applies exclusively to the bare-metal BookStack install, not the Docker version. It also assumes you installed via the Ubuntu Installation script:
https://www.bookstackapp.com/docs/admin/installation/#requirements
--------------------------------------------------------------------------
On the machine with the current BookStack instance running, download and run the script from the following webpage:
https://gist.github.com/ssddanbrown/3d5dbebc51ac6ca45837d8a030b07b65
I've also included it in this current directory, it's "bookstack-backup.sh".
Make it executable with "chmod +x bookstack-backup.sh" and run "./bookstack-backup.sh".
This will make an archived .tar.gz file with important bookstack data.
Within it, there are two folders: public-uploads & storage-uploads.
Further, there's also a .env and database.sql file.
In the folders, the names represent where the data was backed up from.
For instance, "public-uploads" from "/var/www/bookstack/public/uploads/".
And "storage-uploads" took files from "/var/www/bookstack/storage/uploads/".
--------------------------------------------------------------------------
On the NEW machine which you'd like to copy data TO, download the Ubuntu installation script. The details on how to do so are here:
https://www.bookstackapp.com/docs/admin/installation/#requirements
DO NOT RUN IT YET! Open it in a text editor and comment out the following function:
# Run the BookStack database migrations for the first time
function run_bookstack_database_migrations() {
cd "$BOOKSTACK_DIR" || exit
php artisan migrate --no-interaction --force
}
AND/OR, go to the line where "run_bookstack_database_migrations" is called, and comment it out too.
Now that you've made your changes, make the script executable ("chmod +x script.sh") run the installation script as root ("sudo ./script.sh").
When you open Bookstack in the browser, it'll give an error, that's fine! That's Good! This is expected and intended behavior.
--------------------------------------------------------------------------
Now that Bookstack is running on the new machine, but not functioning, you can import the SQL database from the old machine to the new one.
https://www.bookstackapp.com/docs/admin/backup-restore/
TEMPLATE COMMAND> mysql -u {mysql_user} -p {database_name} < {backup_file_name}
If you set up BookStack using the Ubuntu Setup Script (and ran it as root, as you're supposed to), go to the file location of the backup you want to restore to this machine.
The actual command to restore the database will be something like:
$ mysql -u root -p bookstack < database.sql
With "bookstack" likely being the name of the NEW machine's database, and database.sql likely being the name of the OLD machine's database backup. It'll also prompt you for a password. If the user is root, then the password is simply the root password for the machine.
Now, remember those file paths from before?
Copy the contents of "public-uploads" from your backup to "/var/www/bookstack/public/uploads/" on the new server.
Also copy the contents of "storage-uploads" to "/var/www/bookstack/storage/uploads/" on the new server.
LASTLY, there's a ".env" file that also should be in your backup. If you need to copy anything from the old to the new, go ahead (though DO NOT copy APP_KEY as it should be unique per bookstack install) and leave the APP_URL as-is.
Reload the web page, and it should work now!
1 Comment
Update this for clarity, and separate "Backup" and "Restore" as two different pages.