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

**URL:** <https://meta.discourse.org/t/powershell-script-for-sysadmin-to-regularly-download-backups-from-server-to-computer/280983>\
**Category:** Extras\
**Tags:** backups\
**Created:** [October 4, 2023, 1:10am UTC](https://meta.discourse.org/t/powershell-script-for-sysadmin-to-regularly-download-backups-from-server-to-computer/280983 "2023-10-04T01:10:40Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![Ivan\_Rapekas](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ivan_rapekas/32/248924_2.png) [@Ivan\_Rapekas](https://meta.discourse.org/u/Ivan_Rapekas)\
**Post date:** [October 4, 2023, 10:16am UTC](https://meta.discourse.org/t/powershell-script-for-sysadmin-to-regularly-download-backups-from-server-to-computer/280983/4 "2023-10-04T10:16:07Z")

</div>

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

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](https://community.chocolatey.org/packages/rsync) to install `cwrsync`. After installation it’s just needed to add some lines at the end of the cmd-file + create a schedule:

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

```

For example:

```bash
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:

```plaintext
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.

---

_[View the full topic](https://meta.discourse.org/t/powershell-script-for-sysadmin-to-regularly-download-backups-from-server-to-computer/280983)._
