A simple backup script in powershell
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Yorick Barbanneau 4ada9568c4 First Commit 4 months ago
bin First Commit 4 months ago
etc First Commit 4 months ago
log First Commit 4 months ago
README.md First Commit 4 months ago
backup.ps1 First Commit 4 months ago


Powershell Backup Script

This is a simple backup script write in Powershell for Microsoft Windows. It needs 7za and rclone executable into the ./bin directory to work properly.

You must configure it with JSON files, one example is provided in ./etc/example.json.


powershell -File backup.ps1 [-conf ./etc/example.json] [-log ./log/example.log] [-debug]
  • -conf : configuration file (JSON), default ./etc/backup.json
  • log : log file, default $false
  • -debug : verbose output on stdout (not log file)

Configuration example

Here is the example.json file :

    "actions" : 
            "name" : "document_backup",
            "source" : "C:\\Users\\people\\document",
            "dest" : "\\\\backup_srv\\srv01\\",
            "type" : "compress",
            "options" : {
                "-mx" : 3,
                "-mmt" : 4,
                "-xr@" : "C:\\backup\\etc\\7z\\exclude.txt"
            "username" : "bkp_example",
            "pass" : "<secure_string>"
            "name" : "project_copy",
            "source" : "C:\\Users\\people\\project",
            "dest" : "X:\\",
            "type" : "clone",
            "options" : {
                "--exclude" : "*.zip"
            "name" : "database_backup",
            "source" : false,
            "dest" : "X:\\databases",
            "type" : "dump_mssql",
            "options" : {
                "server": "localhost",
                "instance" : "SQL2016",
                "databases": "mydatabase",
                "compression" : false 

All actions performed by the script are defined by actions [...] object :

  • name : name of the action, it will be use as filename for the .zip output in compress type (see below)
  • source : the source path, can be {{tmpdir}} to give the temporary folder
  • dest : the destination path, can be a network path (like \\<host>\<path> ) can be {{tmpdir}} to give the script temporary folder.
  • type define the action :
    • compress : zip all files on the source directory and put it into dest
    • clone : use rclone to sync source and destination
  • options : options to command line (7za or rclone) or for modude (dump_mssql)
  • username : user name for destination network share (if needed)
  • pass: password for destination network share (if needed)

dump_mssql action

This action backup Microsoft SQL Server databases, for this one, source must be false. Here are options :

  • server : MSSQL Server, required parameter
  • instance : Server instance, required parameter
  • compression : activate compression output (zip format - default false)
  • databases : list of databases to be backuped (default all)

You must execute backup script with an user that have the right of backupping MSSQL databases. For now, authentication for databases export is not supported. The user that run the MSSQL daemon must have right to access destination path.

temporary folder

You can use {{tempdir}} in source or destination to specify a temporary directory (formely <script_folder>\tmp). This can be useful, for example, when you want to dump database but use 7zip to compress them :

  • first action dump databases to {{tempdir}}
  • second action compress files in {{tempdir}} to final destination

Password for network share

In this script, network share need a password. password must be created on the machine which execute the script with following command "

"PassW0rd" |  ConvertTo-SecureString -AsPlainText -Force | ConvertFrom-SecureString

Copy-paste the result in your json file into pass (in example, replace <secure_string>).


Until I'm a Linux/*BSD system administrator, I'm not too familiar with Windows system, in particular with MSSQL command line backup tool. So I could do some misktakes, if i do then you can contact me on the fediverse @ephase@toot.aquilenet.fr (and if you have some questions, bug reports, suggestions too).


Do what you want and feel free to send me a message or offer me a beer if you come near Bordeaux - France.