Setting up a backup on B2 / DONE

https://www.backblaze.com/

  1. Create an account in the system https://www.backblaze.com/

  2. Activate B2 cloud storage for this: Log in to your account -> My Settings -> Enabled Products -> [+] B2 Cloud Storage

  3. Create a basket where we will save:

  4. ПAfter that we need to create an App key that can only make a record without the ability to delete the already created backup unfortunately it can not be done through the panel so we created a script that can create a secure key through API backblaze)

To do this we need to:

  1. Clone repo:

    cd /root/
    git clone https://gitlab.com/BoxExchanger-public/b2-backups.git
  2. Go to the project folder:

    cd b2-backups
  3. Install Packages:

    npm i
  4. Get Master KEY (must be changed after creation)

  5. Create a key:

    npm run new-key

    B2 application key ID: keyID obtained in the previous step B2 application key: applicationKey obtained in the previous step

    B2 buckets ID: Buckets -> Your bucket -> Bucket ID

  6. Copy the obtained keys to install them on our server. (temporarily save them in a text file)

  7. Recreate the key obtained at step 4.4 so that the old one is no longer available (it is no longer necessary to copy it)

  8. Install rclone on the server.

  9. Install the obtained keys on the server using the following commands:

    rclone config

    Next, we will be asked to answer questions:

    e/n/d/r/c/s/q> n
    name> b2
    Storage> 5
    account> (App Key Id c шага 4.6)
    key> (App Key c шага 4.6)
  10. Configure backup.sh to properly create the backup and notify the administrator.

    cd /root/b2-backups
    nano backup.sh

    Configuring the block # -- Configuration --

    backup.sh
    # rclone remote name.
    RCLONE_REMOTE="b2"
    # b2 bucket name.
    B2_BUCKET="name-project"
    # Telegram Bot Token
    BOT_TOKEN="1234567890:ABCDEF1234567890ABCDEF1234567890ABC"
    # (list) of Telegram Chat IDs.
    # e.g: CHAT_IDS=("1234567890" "0987654321")
    CHAT_IDS=("1234567890")
Configuration Descriptions: \
**RCLONE\_REMOTE**: The name of the rclone configuration. This was specified in step 6 as name, for example, b2.
**B2\_BUCKET**: The name of the bucket in BackBlaze, which was set in step 3.
**BOT\_TOKEN**: The token for your Telegram bot, obtained from @BotFather. Make sure to start the bot by sending the /start command.
**CHAT\_IDS**: The Telegram IDs of the clients who should receive notifications about backup statuses. You can get your Telegram ID by using the bot @myidbot.

8. Give permissions to run the bash-script file backup.sh

```bash
chmod +x backup.sh
```

 If the script did the job correctly the last line will be:\
`Backup completed successfully.`\
You should also receive a message in .telegram: \
`📦 Backup on`` `_`hostname`_` ``completed successfully.`

9. Check the work of the backup script

```bash
./root/b2-backups/backup.sh
```

10. Set auto backup by crown (in the example every day at 4am server time usually GMT).

```bash
(crontab -l; echo "0 */4 * * * bash /root/b2-backups/backup.sh >> /tmp/bk.log 2>&1") | crontab -
```

Root privileges are required for the script to work. By default, the script looks for the API configuration in the folder /var/www/exchanger-api/config/app_config.json. If you have a different way fix it in the BOXEXCHANGER_API_PATH fily backup.sh in section # -- Init Default Vars -- It is mandatory to have a uri to mongodb in the configuration file

Last updated