Skip to content

Plugin to backup & restore your strapi installation (database + uploads) from admin panel.

License

Notifications You must be signed in to change notification settings

8byr0/strapi-plugin-backup-restore

Repository files navigation

Strapi Backup & Restore plugin

Add backup and restore features directly inside your strapi admin panel.

⚠️ READ FIRST ⚠️

  • This plugin is not actively maintained (I'm definitely open to PR but lack of time)
  • Compatibility with strapi v4 is not available (only v3 is currently supported)

Overview

Backup restore plugin dashboard

Supported databases:

  • mysql
  • sqlite
  • postgre
  • mongodb (not implemented yet)

Installation

Install package from npm

npm i strapi-plugin-backup-restore --save
# or
yarn add strapi-plugin-backup-restore

Rebuild your admin ui

yarn build
# Or launch with admin watch enabled
yarn develop --watch-admin
npm run develop -- --watch-admin

Create a private/backups folder. This folder will be used to store your backups.

mkdir -p private/backups && touch private/backups/.gitkeep

Add this directory to your server config (otherwise in dev your server will restart on every new backup):

// config/server.js
module.exports = ({ env }) => ({
  host: env("HOST", "0.0.0.0"),
  port: env.int("PORT", 1337),
  admin: {
    auth: {
      secret: env("ADMIN_JWT_SECRET", "32a00a220c916908e0efca2b8117262f"),
    },
    // Add this line
    watchIgnoreFiles: ["**/private/**"],
  },
});

You should also add to your .gitignore the following:

private/backups/\*
!private/backups/.gitkeep

Usage

Prerequisites

MySQL

mysqldump command must be available in your environment.

Sqlite

Working out of the box.

Postgres

pg_dump must be available in path. libpq may be used to have it without a whole Postgres installation.

You can manually specify pg_dump path in plugin config like so:

// config/plugins.js
module.exports = () => ({
	"backup-restore": {
		postgres: {
			// Update with your path
			pathToPgDump: "/usr/local/opt/libpq/bin/pg_dump",
		},
	},
});
// docker variant:
module.exports = () => ({
	"backup-restore": {
		postgres: {
			docker: "container-name", // eq. { mode: "local", container: "container-name" }
			// or
			docker: {
				mode: "local",
				container: "container-name",
				path: "docker", // path to command. Not required, default = "docker"
			},
			// or
			docker: {
				mode: "socket",
				container: "container-name",
				socket: "http://socket-url", // not required, default = "/var/run/docker.sock"
				file: true, // boolean or function (originPath: string) => string;
			}
		},
	},
});

Manual backup

Navigate to your admin panel > plugins (left sidebar) > Backup & Restore

Click on Manual Backup to trigger a backup.

Scheduled backup

Edit config/functions/cron.js and add the following cron job.

// config/functions/cron.js
module.exports = {
  /**
   * Trigger a backup at 04:00 every day
   */
  "0 4 * * *": async () => {
    console.log("Starting backup from cron...");
    const backupID = Date.now().toString();

    await strapi.plugins["backup-restore"].services["backup-tools"].runBackup(
      backupID,
      false, // Tells if it's a manual backup, well it's not
      true, // Backup database
      true // Backup files
    );
    console.log(`Backup ${backupID} finished`);
  },
};

Permissions

Backup restore plugin permissions setup You can manage per-scope permissions directly from admin panel.

Backup structure

Your backup contains both database and uploaded files (content of public/uploads). It is a zip file where you'll find:

  • database.sql: a full backup of the database used by strapi
  • uploads.zip: your uploads folder content

Roadmap

Backup

  • Backup from mysql
  • Backup from postgre
  • Backup from sqlite
  • Backup from mongodb
  • Backup local uploads (from public/uploads)
  • Save backup to remote storage (Google drive, one drive, dropbox...) with a tool like rsync
  • Backup uploads from remote provider

Restore

  • Restore to mysql
  • Restore to postgre
  • Restore to sqlite
  • Restore to mongodb
  • Fetch backup from remote storage (Google drive, one drive, dropbox...) with a tool like rsync
  • Restore uploads to remote provider

Disclaimer

MIT license

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

I (or any contributor) could not be responsible for any data loss while using this plugin. Backup feature is quite simple and globally safe (if it fails then you only have a failed backup) but restore is more tricky and external factors involved during the process may break your installation.

Dependencies

There are not a lot of dump clients available on npm and I was in a hurry when creating this plugin so I picked mysqldump which has not been updated since june 2020. A better implementation would be to remove that package / contribute to its development.

About

Plugin to backup & restore your strapi installation (database + uploads) from admin panel.

Resources

License

Stars

Watchers

Forks

Packages

No packages published