@athill/computer-refresh v0.0.3
computer-refresh
Status: Work in progress - not ready for production. Restore functionality has not yet been implemented.
computer-refresh is a JavaScript library to automate and document backing up and restoring your files from one computer to another.
- Declarative Configuration: The backups are defined in a
yamlconfiguration file that documents the files you are backing up. - Deep Copies: The directory structure of the source files is copied so common file names do not clobber each other and context is not lost.
- Flexible: Succinct syntax to copy virtually anything to anywhere.
Installation
$ npm i -S computer-refreshUsage
The idea is to document that which can be automated when moving from computer to computer, so my intended usage is to create a personal repository (e.g, laptop-backup) with this installed where the README is composed of sets of instructions for the backup and restore processes that this script doesn't help automate (e.g., install nodejs on the target computer). The hope is that between the configuration file and the instructions, my backup/restore process is documented and partially automated.
To use run it in another program:
const { cli } = require('@athill/computer-refresh');
// run computer-refresh
cli();To run from the command line in this project
$ ./bin/run COMMAND CONFIGFILEWhere COMMAND is either backup or restore and CONFIGFILE is a YAML file formatted as described below.
Both commands can take a --verbose|-v argument to provide more output
restore only restores the mappings. The other sections do not make sense for a restore
backup can restrict what gets backed up with --app-config|-a, --mappings|-m, and --listings|-l flags. Providing either no or all of these flags will run all sections; otherwise only the sections indicated by the flags will run.
Configuration
Some example configuration will probably help
common:
destination: ~/cloud-provider/computer-refresh
listings:
applications: /Applications
code: ~/Code
mappings:
- from: ~
to: home
files:
- .git-completion.bash
// ...
- from: ~/Documents/recipes
to: recipes
secure:
destination: ~/secure-computer-refresh
mappings:
- from: ~/.m2
to: home/.m2
pattern: '*.xml'
// ...
app-config:
from: ~/Code
to: app-config
files:
include:
- .env
directories:
exclude:
- node_modules
include:
- .ideaIn this example, I'm backing up secure files to my desktop and non-secure (common) files to a cloud provider. The top-level labels are arbitrary. Each label has at least destination and mappings keys.
destination is the root directory to back up files (will be created if it does not exist).
Symbolic links encountered are documented in <destination>/links.sh
listings dumps a top-level directory list into <label>.txt, so in the example, applications.txt would contain a listing of the /Applications directory.
mappings works as follows:
- If there is only a
fromand atoentry, it willcp -rf $from/* $destination/$to. Note that it does not copy the directory itself, but copies into thetodirectory. Thetodirectory structure will be created if it does not exist. - If there is a
patternargument, it will be appended to the copy source in place of the asteriskcp -rf $from/*.xml $destination/$to, for example. - If there is a
fileskey, it will recursively copy each entry. If there is a nested entry (e.g.,foo/bar), thebardirectory will be ensured to exist before copyingbar.
app-config is intended to pluck files not in source control from programming projects (e.g., .env, .idea). The keys are as follows:
from- Root of code directoryto- Where to back up the files ($destination/$to)files- Only has anincludekey for files to include (e.g.,.env)directories - Has a key for directories to include (e.g.,.idea) and exclude, meaning not to traverse (e.g.,node_modules`)