Wondering what’s next for npm?Check out our public roadmap! »

server-backup

1.0.4 • Public • Published

ServerBackup

A CLI application that allows you to backup what you want and when you want from your PC/server to ANY CLOUD/DESTINATION supported by rclone.org.

Table of Contents

  1. Documentation
    1. Requirements
    2. Installation
    3. How to use it
    4. How it works
    5. sb.config.json
    6. sb.sources.json
    7. Commands
    8. Questions
  1. Support
  2. License

Documentation

Requirements

  1. First, make sure you have the latest version of Node.js installed.
  2. Make sure rclone.org installed and the remote that you want to backup to is configured and working(we just need the remote name here).
  3. ServerBackup relies on mysqldump and mongodump to backup MySQL and MongoDB databases, so make sure these tools are installed if you are planning to backup these databases.

Installation

Run:

npm install server-backup -g

How to use it?

Go to an empty folder that you have permissions to write into it and run:

server-backup b now

How it works

ServerBackup needs two files in the directory that you run it within it, these files are sb.config.json and sb.sources.json, so when you run it for the first time it will ask you to create these configurations and sources files then it will be able to continue.

ServerBackup currently able to create a daily, weekly, monthly and manually backups, the manual backup is the backup that you can create manually at any time without a schedule.

sb.config.json

ServerBackup uses this file to save its configurations, here is a sample of this file:

{
  "remoteName": "gdrive",
  "remotePath": "Apps/ServerBackup",
  "monthlyLimit": 4,
  "weeklyLimit": 4,
  "dailyLimit": 30,
  "backupAtHour": 4,
  "backupAtMinute": 30
}

You can create this file manually by using any text editor or you can let ServerBackup generates it for you, here is what every configuration means:

  • remoteName: (String) The name of the remote that you created using rclone.
  • remotePath: (String) The path on the remote that you want the backups to live with(for example and for this configuration a backup will looks like Apps/ServerBackup/daily/2019-07-28-0430).
  • monthlyLimit: (Number) How many backups should remain in the monthly folder, when this number reached and ServerBackup wants to create a new backup it will delete the oldest backup first.
  • weeklyLimit: (Number) How many backups should remain in the weekly folder, when this number reached and ServerBackup wants to create a new backup it will delete the oldest backup first.
  • dailyLimit: (Number) How many backups should remain in the daily folder, when this number reached and ServerBackup wants to create a new backup it will delete the oldest backup first.
  • backupAtHour: (Number) At which hour(24-hour clock) you want this backup to run.
  • backupAtMinute: (Number) At which minute you want this backup to run.

sb.sources.json

ServerBackup uses this file to save the sources, here is a sample of this file:

[
  {
    "type": "files",
    "archive": true,
    "path": "/media/mohammed/My Passport/Dir/htdocs/my-files",
    "name": "my-files"
  },
  {
    "type": "files",
    "archive": false,
    "path": "/media/mohammed/My Passport/Dir/Pictures/"
  },
  {
    "type": "file",
    "path": "/media/mohammed/My Passport/Dir/Pictures/featured.jpg"
  },
  {
    "type": "mySQL",
    "DbName": "tajer",
    "DbUser": "root",
    "DbPassword": ""
  },
  {
    "type": "mySQL",
    "DbName": "ServerBackupTest",
    "DbUser": "root"
  },
  {
    "type": "mongoDB",
    "DbName": "ServerBackup"
  }
]

You can create this file manually using any text editor or you can let ServerBackup generate it for you.

The sources are self-explained, you can have as many sources as you want, the sources will run sequentially for many reasons, here is an explanation for these sources:

  • files: In this source you have a bunch of files in a local folder and you want to upload them to your cloud, you can archive them(zip them) then upload them or you can upload them as they, just specify where these files are in path and whether you want to archive them or not in archive and give then a unique name in name.
  • file: In this source you have a file in a local folder and you want to upload it to your cloud, just specify where this file lives in path.
  • mySQL: In this source you have a MySQL database and you want to back it up and upload it to your cloud.
  • mongoDB: In this source you have a MongoDB database and you want to back it up and upload it to your cloud.

Commands

  Usage: server-backup [options] [command]
 
  PC/Server backup CLI app to backup to ANY CLOUD supported by rclone.
 
  Options:
    -V, --version     output the version number
    -h, --help        output usage information
 
  Commands:
    configurations|c  Reset the configurations
    sources|s         Reset sources
    backup|b [now]    Backup, using the existing configurations and sources, or create them if they do not exist.

For example you can run:

server-backup b

or

server-backup backup

To run the backup and create the configurations and sources files if they do not exist.

This option will run the backup in schedule mode, if you want to run the backup immediately you can run:

server-backup b now

or

server-backup backup now

To create/recreate the configurations file run:

server-backup c

or

server-backup configurations

To create/recreate the sources file run:

server-backup s

or

server-backup sources

To get help run:

server-backup -h

or

server-backup --help

Questions

How to daemonized, monitor and keep ServerBackup alive forever.

There are a lot of tools, however, you can use PM2 to achieve that.

  1. First install PM2 by running npm install pm2 -g

  2. Create ecosystem.config.js file in the folder that you specified for ServerBackup(must have write permissions) with the following content:

    module.exports = {
    apps: [{
        name: 'ServerBackup',
        script: 'server-backup',
        cwd: '/path/to/this/folder/',
        args: 'b'
    }]
    };
    

    Please replace /path/to/this/folder/ with the folder path.

  3. Run pm2 start ecosystem.config.js in the same folder.

  4. To stop and delete the process(undo the above step) you can run pm2 delete ServerBackup

Support

This app built to run on Linux PCs/servers, so it may or may not work on your particular PC/Server, please only report an issue if you run a Linux based operating system, unfortunately, I will not be able to test and reproduce the issue in order to fix it on the other platforms.

You are welcome to contribute code and provide pull requests for ServerBackup, also please feel free to suggest or request any features or enhancements.

License

Copyright (c) 2019 Mohammed Al-Mahdawi Licensed under the MIT license.

Install

npm i server-backup

DownloadsWeekly Downloads

3

Version

1.0.4

License

MIT

Unpacked Size

36.5 kB

Total Files

10

Last publish

Collaborators

  • avatar