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 71b5a48637 Add temporary directory init 2 months ago
bin First commit 2 months ago
etc Example corrections 2 months ago
log First commit 2 months ago
README.md Update README with dump_sql options 2 months ago
backup.ps1 Add temporary directory init 2 months ago

README.md

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 can configure it with JSON files, one example is provided in ./etc/example.json

usage

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" : "test"
        },   
        {
            "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
  • dest : the destination path, can be a network path (like \\<host>\<path>
  • 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 modute (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 rigth to access destination path.

disclaimer

This is the very first version of my script, write for my work need. It may not work properly for you. If you have some questions, bug reports, suggestions you can contact me on the fédiverse : @ephase@toot.aquilenet.fr

Licence

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