localbackup
v0.0.4
Published
Utility to make local backups easily and without the hassle.
Downloads
65
Maintainers
Readme
Local Backup 🦄
Utility to make local backups (and now remote) easily and without the hassle. If you like the project you can leave a star! ⭐️
Basic Usage
It's as simple as running the following command:
npx localbackup --source /path/to/source --destdir /path/to/backups-dest --keeplast 10
The above command requires node and npm to be installed. It also works without node and has binaries to run without node.
Installation options
With NodeJS (recommended)
You can run localbackup directly with no installation, just node and npm are required:
npx localbackup
Without NodeJS
You can download prebuilt binaries for the three major operating systems (windows, mac and linux) from the releases page.
Then you can just execute the binary from terminal, windows example:
localbackup.exe --source /path/to/source --destdir /path/to/backups-dest
CLI Options
To see the options available for your version of localbackup you can always run this command:
npx localbackup --help
Options:
| Option | Description | | --- | --- | | -s, --source | full path of the file or directory to be backed up | | -d, --destdir | full path of the destination directory where the backup file will be stored | | -t, --filetype | file type of the backup file (zip or tar) (default: "zip") | | -p, --prefix | prefix to be added to the backup file name (default: "backup") | | -k, --keeplast | number of backups to keep (olders with the same prefix will be deleted) | | -sp, --storageprovider | storage provider to use (local, s3) (default: "local", no config needed) | | -y, --yes | answer yes to all questions (default: false) | | -h, --help | display help for command |
Usage:
npx localbackup [options]
Keeplast option
The --keeplast
option indicates how many backup copies to keep. When executing the command and
after completing the backup, all files within the destination folder that match the
prefix (--prefix
option) and the extension (--filetype
option) will be searched and only the
specified amount will be kept (including the one generated in the current execution), the rest will
be permanently deleted.
This option is especially useful when working with cron jobs and want to keep only a specific number of backups to save space or for whatever reason.
If no value is specified, the deletion process will be skipped.
Examples
Backup folder and keep only the last 10 backups on the destination directory:
npx localbackup --source /path/to/source --destdir /path/to/backups-dest --keeplast 10
Backup folder and keep only the last 10 backups using s3 as destination:
export LOCALBACKUP_S3_ENDPOINT="s3.us-west-002.backblazeb2.com"
export LOCALBACKUP_S3_BUCKET="mybucket"
export LOCALBACKUP_S3_ACCESS_KEY="myaccesskey"
export LOCALBACKUP_S3_SECRET_KEY="mysecretkey"
npx localbackup --source /path/to/source --destdir /path/to/backups-dest --keeplast 10 --storageprovider s3
Backup single file:
npx localbackup --source /path/to/file.png --destdir /path/to/backups-dest
Change destination file prefix:
npx localbackup --source /path/to/source --destdir /path/to/backups-dest --prefix mycustombackup
Run with no user confirmation (useful for cronjobs):
npx localbackup --source /path/to/source --destdir /path/to/backups-dest --keeplast 10 --yes
Store backups in S3 bucket
localbackup allows you to use an S3 bucket as a destination for your backups. To use this feature, you must first set up environment variables that tell localbackup which credentials to use to connect to S3:
- LOCALBACKUP_S3_ENDPOINT: S3 endpoint (optional), useful for compatible providers, not necessary for native S3
- LOCALBACKUP_S3_BUCKET: Bucket name (required)
- LOCALBACKUP_S3_ACCESS_KEY: Access key (required)
- LOCALBACKUP_S3_SECRET_KEY: Secret key (required)
After setting up the environment variables, you can continue using localbackup normally, and to
activate S3, you just need to add the -sp (--storageprovider)
option to the command:
npx localbackup --source /path/to/source --destdir /path/to/backups-dest --storageprovider s3
The above command creates backups and saves them to S3. All other options work the same way.
Usage with cron jobs
Cron jobs are scheduled tasks that run automatically at specified times or intervals on a Unix-based system.
You can easily use localbackup inside a cron job to periodically backup files and folders.
This is an example of cron expression that create backups of directory every day at 1:00 PM and only keep the last 10 backups:
0 13 * * * npx localbackup --source /path/to/source --destdir /path/to/backups-dest --keeplast 10 --yes
- Read more about cron jobs: https://www.freecodecamp.org/news/cron-jobs-in-linux/
- Easily create cron expressions: https://crontab.guru/