Powershell script for sysadmin to regularly download backups from server to computer

Good point, thanks for the script. Let me share rsync version :slight_smile: .

In the example below sql and attachments are synchronized separately. There is no need to include attachments into backup file. No need to delete old backups as well.

I use Chocolatey to install cwrsync. After installation it’s just needed to add some lines at the end of the cmd-file + create a schedule:

C:\ProgramData\chocolatey\lib\rsync\tools\cwrsync.cmd

For example:

rsync -rvm --delete --ignore-errors --ignore-existing --size-only --chmod=ugo=rwX -e "ssh -i /cygdrive/c/Users/user1/.ssh/id_rsa" login@host:/var/discourse/shared/standalone/backups/default/ /cygdrive/d/backup/forum/db/

rsync -rvm --delete --ignore-errors --ignore-existing --size-only --chmod=ugo=rwX -e "ssh -i /cygdrive/c/Users/user1/.ssh/id_rsa" login@host:/var/discourse/shared/standalone/uploads/ /cygdrive/d/backup/forum/uploads/

Note 1: Use /cygdrive/c/ instead of C:, read the cmd-file for reference and syntax.

Note 2: You can modify command to use password instead of ssh-key (PEM-format)

Note 3: If you don’t put a slash after the dump/ folder, rsync will copy the folder, but if you do, it will only copy the contents of the folder.

Note 4: if chocolatey will upgrade cwrsync, it creates a backup of previous cmd at the same folder. You need to copy your commands to new cmd manually to continue backups.

Important: Set the same rule into Scheduler as OP wrote. The scheduler line is:

C:\ProgramData\chocolatey\lib\rsync\tools\cwrsync.cmd >> d:\backup\cwrsync.txt 2>&1

It will append the output to the file cwrsync.txt. That’s all.

3 Likes