1.0.15 • Published 1 year ago

@double-man/node-full-backup v1.0.15

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

Welcome to the GitHub repository for NodeFullBackup, the all-encompassing package designed for your data preservation needs. NodeFullBackup offers a seamless solution for taking database and file backups concurrently, ensuring comprehensive protection for your digital assets. Tailored for versatility, it’s perfect for individual developers and organizations alike, safeguarding data across various systems. Explore our documentation to learn how NodeFullBackup can fortify your backup strategy and provide a reliable safety net for your projects.

Currently, this package supports only MongoDB.

Installation

NodeFullBackup is available as an npm package, allowing for easy installation using the command below:

npm i @double-man/node-full-backup

Simple Usage

You can effortlessly integrate and utilize this package with a single step: simply copy the following code snippet wherever you need it

import FullBackup from  '@double-man/node-full-backup';

const backup = new FullBackup({
		   //backup output address
	    outputPath: path.resolve('./backup'),
	    //folders list for backup
	    folders: [path.resolve('./public')],
	    //remove backup files after 1 day
	    expireDays: '1d',
	    //take backup every 6 hours
		   cornExpression: '0 */6 * * *', 
	    database: {
			username: 'database_username',	
			password: 'database_password',
			database: 'database_name',
		    host: 'localhost',
		    port: 27017
	    }, 
  }
});
   
// start cronJob for backup
backup.start();

Parameters

NodeFullBackup offers a variety of configurable parameters to tailor the backup process to your needs. Below is a detailed table outlining all available options:

ParameterTypeDescription
outputPathString*The destination folder path for the backup files.
outputNamePrefixStringA prefix for the backup file names.
cronExpressionStringThe cron expression for scheduling backups.
outputTypeStringThe format of the output file: 'zip' or 'tar'.
filesString[]An array of file paths to include in the backup.
foldersString[]An array of folder paths to include in the backup.
expireDaysStringThe number of days after which old backup files will be removed.
afterBackupFunction(filePath)A callback function that provides access to the backup file path after each backup operation.
databaseObjectProperties for database configuration are detailed in the subsequent table.

Database Object Properties

Configure your database settings using the properties listed in the table below:

ParameterTypeDescription
usernameStringThe username for database access.
passwordStringThe password for database access.
databaseString*The name of the database to back up.
hostString*The host address of the database.
portNumberThe port number for connecting to the database.

* Required fields

Upload Backup To GoogleDrive

To automatically upload your backup file to Google Drive, implement the following code within the afterBackup callback:

import FullBackup, {uploader} from  '@double-man/node-full-backup';

const backup = new FullBackup({
		...
	    //this function will execute after each backup
		afterBackup: (filePath: string) => {
			uploader.googleDrive(path_of_google_key_json , filePath , google_drive_folder_id)
		} 
 });
    
 // start cronJob for backup
 backup.start();

Obtain your Google JSON key by following the instructions in this guide, and ensure that your Google Drive service is activated.