DirBackUpper

DirBackUpper

Source:

The WSH (Windows Script Host) CLI that updates or mirrors directories according to the schema defined in a JSON file.

Requires

Methods

(static) archiveDir(srcDir, dest, optionsopt) → {typeDeflateResult|Array.<typeDeflateResult>|string|Array.<string>}

Source:

Compresses the directory into archive file (ZIP or RAR).

Example
var dirBkup = Wsh.DirBackUpper; // Shorthand

var srcDir = 'C:\\Users';
var dest = 'D:\\BackUp\\Users\\#{yyyy}\\#{MM - 1}';

dirBkup.archiveDir(srcDir, dest, {
  archiveType: 'ZIP',
  ignoredRegExp": ["\\.git.*"],
  archiveOptions": {
    exe7z: exe7z
    dateCode: 'yyyy-MM-dd_hhmmss',
    compressLv: 9,
    password: 'This is mY&p@ss ^_<',
  },
  logger: 'warn/winEvent' // See https://github.com/tuckn/WshLogger
});
Parameters:
Name Type Attributes Description
srcDir string

The source directory path to back up.

dest string

The destination directory path.

options object <optional>

Optional parameters.

Properties
Name Type Attributes Default Description
archiveType string <optional>
'ZIP'

The archiving method, 'ZIP' (default) or 'RAR'

archiveOptions typeDeflateZipOption | typeDeflateRarOption <optional>

Optional parameters. See Wsh.ZLIB.typeDeflateZipOption and Wsh.ZLIB.typeDeflateRarOption.

forEachSubDir boolean <optional>
true

Compresses each sub directory in the specified source directory.

rootFilesName boolean <optional>
'RootFiles'

When forEachSubDire option is true, root files are archived as this name. (default: 'RootFiles')

includesEmptyDir boolean <optional>
false

Compresses empty directories.

includesSymlink boolean <optional>
false

Compresses symbolic links.

matchedRegExp string | Array <optional>

When forEachSubDir option is true, matched RegExp only for the root directories and files in the source. e.g. "^[^.].+$"

ignoredRegExp string | Array <optional>

When forEachSubDir option is true, ignored RegExp only for the root directories and files in the source. e.g. "\.git.*"

logger Logger | string | object <optional>

The Logger instance or create options. See Wsh.Logger.create.

isDryRun boolean <optional>
false

No execute, returns the string of command.

throws boolean <optional>
false

Throws a error.

transportsLog boolean <optional>
true

Outputs Wsh.Logger logs after connecting. See Wsh.ZLIB.typeDeflateResult.

Returns:
  • @see typeDeflateResult. If options.isDryRun is true, returns string.
Type
typeDeflateResult | Array.<typeDeflateResult> | string | Array.<string>

(static) backupDir(srcDir, destDir, optionsopt) → {void}

Source:

Backs up the directory.

Example
var dirBkup = Wsh.DirBackUpper; // Shorthand

var srcDir = 'C:\\Users';
var destDir = 'D:\\BackUp\\Users\\#{yyyy}\\#{MM - 1}';

dirBkup.backupDir(srcDir, destDir, {
  sync: 'MIRROR',
  comparison: 'CONTENT',
  ignoredRegExp: 'tmp$',
  logger: 'warn/winEvent' // See https://github.com/tuckn/WshLogger
});
Parameters:
Name Type Attributes Description
srcDir string

The source directory path to back up.

destDir string

The destination directory path.

options object <optional>

Optional parameters.

Properties
Name Type Attributes Default Description
syncMethod string <optional>
'UPDATE'

The synchronization method. "UPDATE" or "MIRROR".

comparison string <optional>
'TIME'

"TIME" or "CONTENT".

isRecursive boolean <optional>
true

Copies sub directories.

copiesEmpDir boolean <optional>
false

Copies empty directories.

includesSymlink boolean <optional>
false

Copies symbolic link.

matchedRegExp string | Array <optional>

e.g. "\w+\.txt$"

ignoredRegExp string | Array <optional>

e.g. "\.tmp$"

logger Logger | string | object <optional>

The Logger instance or create options. See Wsh.Logger.create.

transportsLog boolean <optional>
true

Outputs Wsh.Logger logs after connecting. See Wsh.Logger.transport.

isDryRun boolean <optional>
false

No execute, returns the string of command.

throws boolean <optional>
false

Throws a error.

Returns:
Type
void

(static) backupDirUsingSchema(schema, taskNameopt, optionsopt) → {void}

Source:

Backs up the directories.

Example
var dirBkup = Wsh.DirBackUpper; // Shorthand
var schema = {
  description: 'Example Schema WshDirBackUpper',
  components: {
    dest: '\\\\MyNas\\BackUp',
    exe7z: 'D:\\My Apps\\7-Zip\\7z.exe',
    anyVal1: null
  },
  tasks: {
    userAppData: {
      description: 'Example task with options',
      srcDir: 'C:\\Users\\Default\\AppData',
      destDir: '${dest}\\AppData\\#{yyyy}\\#{MM-dd}',
      method: 'UPDATE',
      options: {
        comparison: 'TIME',
        ignoredRegExp: [
          'Windows\\\\WebCache',
          'Packages\\\\.*Cache\\\\',
          '\\.mui$',
          '\\.settingcontent-ms$'
        ]
      }
    },
    'userAppData:zip': {
      srcDir: 'C:\\Users\\Default\\AppData',
      destDir: '${dest}\\AppData\\archives',
      method: 'ARCHIVE',
      options: {
        ignoredRegExp: ['\\.git.*'],
        archiveType: 'ZIP',
        archiveOptions: {
          exe7z: '${exe7z}',
          dateCode: 'yyyy-MM-dd',
          compressLv: 9,
          password: 'This is mY&p@ss ^_<'
        },
        additionalArchiveOptions: {
          'Visual Studio Code': {
            excludingFiles: [
              '*\\data\\user-data\\*Cache*\\*',
              '*\\data\\user-data\\logs\\*',
              '*\\data\\user-data\\*\\*\\LOCK'
            ]
          }
        }
      }
    },
    'appLog:current': {
      srcDir: 'D:\\AppLogs\\#{yyyy}\\#{MM}',
      destDir: '${dest}\\AppLogs\\#{yyyy}\\#{MM}',
      method: 'MIRROR',
      options: {
        comparison: 'CONTENT',
        matchedRegExp: '\\.csv$'
      }
    },
    'appLog:lastMonth': {
      available: false,
      srcDir: '${anyVal1}:\\AppLogs\\#{yyyy\\[MM-1]}',
      destDir: '${dest}\\AppLogs\\#{yyyy\\[MM-1]}',
      method: 'MIRROR',
      options: {
        comparison: 'TIME',
        matchedRegExp: '\\.csv$'
      }
    }
  }
};

dirBkup.backupDirUsingSchema(schema, 'work:*', {
  logger: 'info/console',
  overwrites: { anyVal1: 'E' }
});
// Only process appLog:current. appLog:lastMonth is not processed because available is false.
Parameters:
Name Type Attributes Description
schema typeSchemaBackUpper
taskName string <optional>

The task name to back up.

options object <optional>

Optional parameters.

Properties
Name Type Attributes Default Description
overwrites object <optional>

Ex. { anyVal1: 'myP@ss', anyVal2: 'p_w_d' }

logger string | Object <optional>

See options of Wsh.Logger.create

isDryRun boolean <optional>
false

No execute, returns the string of command.

Returns:
Type
void