The easiest way to backup and restore Strapi

Because of no officials documentation about Strapi maintenance, so we will explain two keys of this operation is backup and restore with fully data and no need any extra tasks to migration

Backup

  1. We have to have access to Strapi server farm through SSH
  2. Three parts have to be backed up from Strapi is app code, data file (if needed) and database. Please locate them on your server and get enough information about permissions to run some tasks like compress, pg_dump, cp or rsync
  3. About database, run

    pg_dump -U (strapi_user) -Fc (strapi_db_name) > backup_name.sql

  4. About app code and data file,
    Notice: don’t include node_modules into compress file, it’s unnecessary

    tar -cf (compress_file_name).tar.gz (list of folders to backup)

  5. Rsync or scp all file from step 3 and step 4 to our backup servers

Restore

  1. Extract app code to the specific folder,

    tar -xf (compress_file_name).tar.gz -C (dest_folder)

  2. About database, access to your database administration interface and create a database

    Ex: with postgreSQL, create database (strapi_backup_db_name);

  3. Access to extracted app code folder recently, modify the database.json in folder config with the current database connection information like

    DATABASE_HOST, DATABASE_NAME, DATABASE_USERNAME, DATABASE_PASSWORD

  4. In the extracted app code folder,

    Re-run: npm install && npm run build
    DEV mode: npm run develop
    PROD mode: NODE_ENV=production npm start

Of course, in the production environment, we still have many extra strategies to completely ensure the server functioning like snapshot, code revision based rsync and git. We will discuss further in the next topic!

1 Like