Skip to content

Instantly share code, notes, and snippets.

@cjus
Last active January 2, 2021 16:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cjus/ce2d082c6b26c60bf28b59cb33658f52 to your computer and use it in GitHub Desktop.
Save cjus/ce2d082c6b26c60bf28b59cb33658f52 to your computer and use it in GitHub Desktop.
NodeJS project backup script

NodeJS project backup script

The following shell script backups up the currrent node project by performing the following actions:

  • Assumes that the back script is bundled with the actual NodeJS projecxt foler.
  • Uses the current directory as the backup file name.
  • Moves to the parent folder to create a tarball using the project name and the current date stamp and excludes the node_modules folder.
  • Lists the backups created using the script.
#!/bin/sh
projectName=${PWD##*/}
cd ..
d=`date +%Y%m%d-%H%M%S`
fname=''${projectName}-$d.tgz
tar pczf $fname --exclude *.log --exclude node_modules ${projectName}
ls -lrt ${projectName}*.tgz

Given a folder called my-cool-project, the created backup would look like this, and would sit in the folder outside of the my-cool-project directory.

my-cool-project-20160707-105046.tgz

Thoughts

Just use Github to tag builds? Sure you should be doing that anyway! The above script is intended to grab the project along with configuration files you might need to backup. Normally you wouldn't store your production config files in your project repo - particularily if PKI certs are involved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment