Extensions:Automatic Backups

From Lorekeeper Wiki
Revision as of 22:42, 15 July 2025 by Liwoyadan (talk | contribs) (I keep forgetting how Wiki formatting works.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
Automatic Backups
Description Sets up in-app automated backups.
Author(s) Mercury
Status Testing
Github extension/auto-backups
LK Version 2.0.0
Uses a Package






Facilitates automatic/scheduled backups of a site's /public directory-- under the assumption that all else (source code) is already backed up by virtue of originating from a different machine in the first place, thus including more would just waste space-- and database. While by default backups are saved to storage/app, it is HIGHLY RECOMMENDED that you configure either an off-server storage location for them or have a solution to move the backups off the server regularly, preferably automatically. To this end, optional Dropbox support is included.

This is more or less just a for-convenience implementation of existing tools, ready to go give or take configuration as desired. Implements spatie/laravel-backup with some pre-configuration as well as support for Dropbox via benjamincrozat/laravel-dropbox-driver.

Installation

Pull the branch and update packages like so:

Installing packages with Composer:
Commands are given as composer [command]; if you have not installed composer globally, they will be php composer.phar [command] instead.
You may need to run composer self-update (assuming you have not recently) before installing package(s). If possible, update to composer v2.x; you may need to use the command composer self-update --2.
If feasible, run composer update.
If you encounter memory issues: Locally, run composer update. Copy the composer.lock file to your site's server.
Run composer install.

Add the following to your .env as desired:

BACKUP_NOTIFICATION_ADDRESS=(email address. can leave out and specify directly in config file if desired)
BACKUP_ARCHIVE_PASSWORD=(optional, but recommended; a strong password (careful of special symbols that may cause issues!) that enables encryption of backups. some server environments may not support encryption effectively (i.e. worked in local testing but not on DH) however)
DROPBOX_TOKEN=(only required for Dropbox support. See below for how to obtain this.) 

Dropbox Setup

To get an access token, you'll need to create a Dropbox app here. Once you've logged in and clicked the "Create App" button:

  1. Choose "Scoped Access"
  2. Choose "App Folder"
  3. Give it a unique and descriptive name; you can use this one app for multiple sites/backups if you wish, so you may want this to be fairly general
  4. Create the app

This will make an app "in development" of which you are the sole user. You can leave this as-is in perpetuity. Once the app itself is created, navigate to the "permissions" tab, and check:

  • files.metadata.write
  • files.metadata.read
  • files.content.write
  • files.content.read

and save these permissions. This is necessary for the app to read and write backups in its folder. Next, navigate back to the settings tab.

  1. Under "Access Token Expiration", select "No expiration"
  2. Click "Generate" under "Generated access token"

This access token is what you'll use to connect your site to Dropbox.

Dropbox (Refresh Token) Installation

If you are looking for an updated branch for this extension on v3 that is compatible with Dropbox changes over the years, you can find a branch here. There are a few adjustments to be aware of when installing this extension now when intending to use Dropbox as a storage method due to Dropbox no longer supporting access tokens that do not expire. Instead, you will have to fetch and use something known as a "refresh token". Follow the steps above in 'Dropbox Setup' to set up your app first.

Similar to the above, instead you will want to set up your .env with:

BACKUP_NOTIFICATION_ADDRESS=(email address. can leave out and specify directly in config file if desired)
BACKUP_ARCHIVE_PASSWORD=(optional, but recommended; a strong password (careful of special symbols that may cause issues!) that enables encryption of backups. some server environments may not support encryption effectively (i.e. worked in local testing but not on DH) however)
DROPBOX_APP_KEY=
DROPBOX_APP_SECRET=
DROPBOX_REFRESH_TOKEN=
DROPBOX_TOKEN_URL=https://${DROPBOX_APP_KEY}:${DROPBOX_APP_SECRET}@api.dropbox.com/oauth2/token

To get some of these values, navigate to the app you created on the Dropbox developers app page here and:

  • You will be able to find the app key and app secret on the Settings page of your created app, above the OAuth2 section
  • With the app key that the page gives you, replace <YOUR_APP_KEY> in this URL with the given key and visit the URL in your browser:
https://www.dropbox.com/oauth2/authorize?client_id=<YOUR_APP_KEY>&response_type=code&token_access_type=offline
  • The above will ask you to authorize the app you made with your Dropbox account. Once authorized, you will receive an authorization code. Replace <AUTHORIZATION_CODE>, <APP_KEY>, and <APP_SECRET> with their relevant values in the following:
curl https://api.dropbox.com/oauth2/token -d code=<AUTHORIZATION_CODE> -d grant_type=authorization_code -u <APP_KEY>:<APP_SECRET>
  • Run that in a terminal window and it will give you a long chunk of text where you will be able to retrieve your app's refresh token value
  • Finish populating your .env with the required values!

With that, the extension's access to your Dropbox should no longer expire. Credits to mho22 at the flysystem-dropbox discussions page for the solution to Dropbox no longer supporting long-lived access tokens.

Configuration

If desired, update config/backup.php to use the "dropbox" disk instead of "local"; you will need to do this for both storage and monitoring, so by default, on lines 121 and 190.

By default, it's configured to cap the space taken by backups at 25 GB and clean up the oldest backup past that. You can adjust this on (by default) line 252 for storage and line 193 for monitoring.

Further configuration options and information, including advanced configuration, can be viewed via the spatie/laravel-backup documentation.

Usage

N/A

Troubleshooting

Find me in the Lorekeeper server!

Images

See Also