https://github.com/tuckn/wshdirbackupper
The WSH (Windows Script Host) CLI that updates or mirrors directories according to the schema defined in a JSON file.
https://github.com/tuckn/wshdirbackupper
backup cli jscript json mirroring schema windows wsf wsh
Last synced: about 23 hours ago
JSON representation
The WSH (Windows Script Host) CLI that updates or mirrors directories according to the schema defined in a JSON file.
- Host: GitHub
- URL: https://github.com/tuckn/wshdirbackupper
- Owner: tuckn
- License: mit
- Created: 2020-08-01T02:01:49.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2024-01-25T22:12:06.000Z (over 1 year ago)
- Last Synced: 2025-04-07T17:19:44.257Z (2 months ago)
- Topics: backup, cli, jscript, json, mirroring, schema, windows, wsf, wsh
- Language: JavaScript
- Homepage: https://tuckn.net/docs/WshDirBackUpper/
- Size: 350 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# WshDirBackUpper
The WSH (Windows Script Host) CLI updates or mirrors or archives directories according to the schema defined in a JSON file.
## Operating environment
Works on JScript in Windows.
## Installation
Download this ZIP and unzip or Use the following `git` command.
```console
D:\> git clone https://github.com/tuckn/WshDirBackUpper.git
D:\> cd WshDirBackUpper
```Now suppose your directory structure looks like this.
```console
D:\WshDirBackUpper\
├─ .wsh\
│ └─ settings.json
└─ dist\
├─ Run.wsf
└─ bundle.js
```## Usage
### Command Line
Copy the directory
```console
> cscript .\dist\Run.wsf backup "C:\Users\Public" "\\MyNas\Archives"
```Archive each sub directory in the directory "C:\Users\Public"
```console
> cscript .\dist\Run.wsf archive "C:\Users\Public" "\\MyNas\Archives"
```### With Schema JSON
The JSON default path to load is _%CD%\.wsh\\settings.json_.
See _.\\.wsh\\settings.json_ as example.Write your backing up schema in the JSON file, for example,
```json
{
"dirBackUpperSchema": {
"tasks": {
"userAppData": {
"srcDir": "C:\\Users\\Default\\AppData",
"destDir": "\\\\MyNas\\BackUp\\User\\AppData",
"method": "MIRROR", // default: "UPDATE"
},
"appLog": {
"srcDir": "D:\\logs\\csv",
"destDir": "\\\\MyNas\\BackUp\\csvLogs",
"method": "ARCHIVE", // default: "UPDATE"
}
}
}
}
```You can also define variables into `components` object.
The defined variable can be used as `${valName}` in `tasks`.```json
{
"dirBackUpperSchema": {
"components": {
"dest": "\\\\MyNas\\BackUp"
},
"tasks": {
"userAppData": {
"srcDir": "C:\\Users\\Default\\AppData",
"destDir": "${dest}\\User\\AppData",
"method": "MIRROR",
},
"appLog": {
"srcDir": "D:\\logs\\csv",
"destDir": "${dest}\\csvLogs",
"method": "ARCHIVE",
}
}
}
}
```You can also use a date code literal to define `srcDir` and `destDir`.
```json
{
"dirBackUpperSchema": {
"tasks": {
"appLog:current": {
"srcDir": "C:\\logs\\csv",
"destDir": "D:\\BackUp\\#{yyyy}\\#{MM}",
"method": "MIRROR",
},
"appLog:lastMonth": {
"srcDir": "D:\\BackUp\\#{yyyy\\[MM-1]}",
"destDir": "\\MyNas\\CsvLogs\\#{yyyy\\[MM-1]}",
"method": "ARCHIVE",
}
}
}
}
```See [WshUtil: parseDateLiteral](https://tuckn.net/docs/WshUtil/Wsh.Util.html#.parseDateLiteral) for the literal.
And can also use backing up options.
```json
"dirBackUpperSchema": {
"tasks": {
"userAppData": {
"srcDir": "C:\\Users\\Default\\AppData",
"destDir": "D:\\Backup\\AppData\\#{yyyy}\\#{MM-dd}",
"method": "MIRROR", // default: "UPDATE"
"options": {
"comparison": "CONTENT", // default: "TIME"
"isRecursive": false,
"copiesEmpDir": true,
"includesSymlink": true,
"matchedRegExp": "\\.csv$",
"ignoredRegExp": [
"Windows\\\\WebCache",
"Packages\\\\.*Cache\\\\",
"\\.mui$",
"\\.settingcontent-ms$"
]
}
},
"appLog:current:rar": {
"srcDir": "D:\\AppLogs\\#{yyyy}\\#{MM}",
"destDir": "\\MyNas\\AppLogs\\#{yyyy}\\#{MM}",
"method": "ARCHIVE",
"options": {
"archiveType": "RAR", // default: "ZIP"
"archiveOptions": {
"dirWinRar": "C:\\My Apps\\WinRAR",
"dateCode": "yyyy-MM-dd",
"compressLv": 0,
"password": "This is mY&p@ss ^_<"
},
"ignoredRegExp": ["^\\.git.*$"]
}
}
}
}
```See below to know all options.
- When the `method` is `UPDATE` or `MIRROR`, You can use [WshDirBackUpper: typeSchemaBackUpperTask](https://tuckn.net/docs/WshDirBackUpper/global.html#typeSchemaBackUpperTask)
- When the `method` is `ARCHIVE` and `options.archiveType` is `ZIP`, You can use [WshZLIB: typeDeflateZipOption](https://tuckn.net/docs/WshZLIB/global.html#typeDeflateZipOption)
- When the `method` is `ARCHIVE` and `options.archiveType` is `RAR`, You can use [WshZLIB: typeDeflateRarOption](https://tuckn.net/docs/WshZLIB/global.html#typeDeflateRarOption)You can use the `schemaBackup` command to perform processing from the schema JSON file.
For example, the below command runs all available backing up tasks defined in the JSON.
```console
> cscript .\dist\Run.wsf schemaBackup *
```Can specify any tasks to run with property names.
```console
> cscript .\dist\Run.wsf schemaBackup appLog:*
```Show the help.
```console
> cscript .\dist\Run.wsf schemaBackup --helpUsage: schemaBackup [overwriteKey:val...] [options]
The command to back up directories defined with a schema JSON
Options:
-V, --version Output the version number
-D, --dir-path The path name where the schema JSON is located. or "cwd", "portable", "userProfile". Default: "cmd" is "%CD%\.wsh"
-F, --file-name A JSON file name. (default: "settings.json")
-E, --encoding The JSON file encoding. (default: "utf-8")
-N, --prop-name A property name of the schema object. (default: "dirBackUpperSchema")
-T, --task Specify the task name to back up. e.g. "work:*" (default: "*")
-L, --logger /. e.g. "warn/popup". (default: "info/console")
-R, --dry-run No execute. Outputs the string of command. (default: false)
-h, --help Output usage information
```See [Wsh.ConfigStore](https://tuckn.net/docs/WshConfigStore/) for the options `--dir-path` and `--file-name`.
and see [Wsh.Logger](https://tuckn.net/docs/WshLogger/) for the options `--logger`.## Installation as Module
(1) Create a directory of your WSH project.
```console
D:\> mkdir MyWshProject
D:\> cd MyWshProject
```(2) Download this ZIP and unzip or Use the following `git` command.
```console
> git clone https://github.com/tuckn/WshDirBackUpper.git ./WshModules/WshDirBackUpper
or
> git submodule add https://github.com/tuckn/WshDirBackUpper.git ./WshModules/WshDirBackUpper
```(3) Include _.\\WshDirBackUpper\\dist\\bundle.js_ into your .wsf file.
For Example, if your file structure is```console
D:\MyWshProject\
├─ Run.wsf
├─ MyScript.js
└─ WshModules\
└─ WshDirBackUpper\
└─ dist\
└─ bundle.js
```The content of the above _Run.wsf_ is
```xml
```
I recommend this WSH file (.wsf) encoding to be UTF-8 [BOM, CRLF].
### Together with another Apps
If you want to use it together with another Apps, install as following
```console
> git clone https://github.com/tuckn/WshBasicPackage.git ./WshModules/WshBasicPackage
> git clone https://github.com/tuckn/WshSmbConnector.git ./WshModules/WshSmbConnector
> git clone https://github.com/tuckn/WshDirBackUpper.git ./WshModules/WshDirBackUpper
or
> git submodule add https://github.com/tuckn/WshBasicPackage.git ./WshModules/WshBasicPackage
> git submodule add https://github.com/tuckn/WshSmbConnector.git ./WshModules/WshSmbConnector
> git submodule add https://github.com/tuckn/WshDirBackUpper.git ./WshModules/WshDirBackUpper
``````xml
```
## Usage as Module
Now _.\\MyScript.js_ (JScript ) can use `Wsh.DirBackUpper`.
Backing up and logging.
```js
var bkup = Wsh.DirBackUpper; // Shorthandvar srcDir = 'C:\\Users';
var destDir = 'D:\\BackUp\\Users\\${yyyy-MM}';bkup.backupDir(srcDir, destDir, {
syncMethod: 'MIRROR',
comparison: 'CONTENT',
ignoredRegExp: 'tmp$',
logger: 'warn/winEvent' // See https://github.com/tuckn/WshLogger
});
```With Schema
Example of using a schema
```js
var bkup = Wsh.DirBackUpper; // Shorthandvar schema = {
description: 'Example Schema WshDirBackUpper',
components: {
exe7z: 'C:\\My Apps\\7-Zip\\7z.exe',
},
tasks: {
userAppData: {
srcDir: 'C:\\Users\\Default\\AppData',
destDir: 'D:\\AppData\\#{yyyy}\\#{MM-dd}',
method: 'UPDATE',
options: {
comparison: 'TIME',
ignoredRegExp: ['Packages\\\\.*Cache\\\\', '\\.mui$']
}
},
'appLog:current': {
srcDir: 'D:\\My App Data',
destDir: '\\\\MyNas\\AppLogs\\#{yyyy}\\#{MM}',
method: 'ARCHIVE',
options: {
archiveType: 'ZIP',
exe7z: '${exe7z}',
dateCode: 'yyyyMMddThhMMss',
compressLv: 9,
ignoredRegExp: ['^\\.git.*']
}
},
'appLog:lastMonth': {
available: false,
srcDir: 'D:\\AppLogs\\#{yyyy\\[MM-1]}',
destDir: '\\\\MyNas\\AppLogs\\#{yyyy\\[MM-1]}'
method: 'MIRROR'
}
}
};bkup.backupDirUsingSchema(schema, 'appLog:*', {
logger: 'info/console'
});
// Only process appLog:current. appLog:lastMonth is not processed because available is false.
```### Dependency Modules
You can also use [tuckn/WshBasicPackage](https://github.com/tuckn/WshBasicPackage) functions in _.\\MyScript.js_ (JScript).
## Documentation
See all specifications [here](https://tuckn.net/docs/WshDirBackUpper/) and also [WshBasicPackage](https://tuckn.net/docs/WshBasicPackage/).
## License
MIT
Copyright (c) 2020 [Tuckn](https://github.com/tuckn)