Backing Up LaunchBox Collection
Tags: gaming, windows, powershell
Published: 2021-01-22 16:29:04

---
title: Backing Up LaunchBox Collection
published: true
date: 2021-01-22 16:24:26 UTC
tags: gaming,windows,powershell
canonical_url: 
---

> Or how I learned to stop worrying and love robocopy

 ![Backing Up LaunchBox Collection](https://jakeg.dev/content/images/2021/01/raiden_marquee.jpg)

After spending a good deal of time importing games, adjusting metadata, and getting everything configured just right, one starts to crave the piece of mind of having a mirrored copy of that collection on another machine _just in case_.

![Backing Up LaunchBox Collection](https://jakeg.dev/content/images/2021/01/Screenshot-2021-01-22-110159.jpg)

Since my CLI-fu leans more Way of the Bash rather than Powershell, I naturally wanted something as trivial as `rsync $MUH_LIBRARY/ coolguy@192.168.1.XXX:/backups/muh_library` and throw that into my crontab running `@daily` or similar. But, even though WSL provides a great dev experience, it doesn't necessarily (nor should it) provide some of the system-level utilities of GNU/Linux (like not having systemd, for example). But obviously, this kind of simple pattern can't be reserved to the majesty of Tux. It's just a bit different and requires some discovery.

Enter: _Task Scheduler_

 ![Backing Up LaunchBox Collection](https://jakeg.dev/content/images/2021/01/Untitled-1.png)

 ![Backing Up LaunchBox Collection](https://jakeg.dev/content/images/2021/01/Screenshot-2021-01-22-110918-1.jpg)

 ![Backing Up LaunchBox Collection](https://jakeg.dev/content/images/2021/01/Screenshot-2021-01-22-110838.jpg)

Cool. Adjust timing to taste.

Now, what's this `launchbox.ps1`? That's going to be the backup script.

```
# Given,

$LOCAL_LAUNCHBOX_PATH = "C:\Users\coolguy\LaunchBox\"
$REMOTE_LAUNCHBOX_PATH = "\\OPENMEDIAVAULT\coolguy\backups\LaunchBox"

# we can mirror local to remote (this will delete files in remote if they've been removed in the source.
# /copy will just copy new files in source to the sink, but since LaunchBox includes it's own DB, I'm using /mir
# Of course, if you only cared about backuping the games and their file organization, /copyall may also suffice

robocopy $LOCAL_LAUNCHBOX_PATH $REMOTE_LAUNCHBOX_PATH /mir

# Since this will output each file as it scans for changes, I'm using Select-Object to "tail" the output. (/np is added to remove progress reporting in the log output as well)

robocopy $LOCAL_LAUNCHBOX_PATH $REMOTE_LAUNCHBOX_PATH /mir /np | Select-Object -last 8

# which will output
#
# Total Copied Skipped Mismatch FAILED Extras
# Dirs : 2098 0 2098 0 0 0
# Files : 2401 0 2401 0 0 0
# Bytes : 62.925 g 0 62.925 g 0 0 0
# Times : 0:00:08 0:00:00 0:00:00 0:00:08
# Ended : Friday, January 22, 2021 10:56:34 AM

 

```

The full script includes some start/end headers and outputs to a script (appending). Check it out:

<!--kg-card-begin: markdown-->
```
$logpath = "$HOME\.launchbox-backup.log"
$start = $(Get-Date -Format 'o')
Write-Output "[$start] MIRRORING LAUNCHBOX TO MEDIAVAULT" | Out-File -FilePath $logpath -Append
robocopy C:\Users\jgori\LaunchBox\ '\\OPENMEDIAVAULT\VaultBackups\launchbox' /mir /np | Select-Object -last 8 | Out-File -FilePath $logpath -Append
$end = $(Get-Date -Format 'o')
Write-Output "[$end] DONE" | Out-File -FilePath $logpath -Append

```

Example,

```
PS C:\Users\jgori> Get-Content .\.launchbox-backup.log

[2021-01-22T10:56:26.0070112-05:00] MIRRORING LAUNCHBOX TO MEDIAVAULT

               Total Copied Skipped Mismatch FAILED Extras
    Dirs : 2098 0 2098 0 0 0
   Files : 2401 0 2401 0 0 0
   Bytes : 62.925 g 0 62.925 g 0 0 0
   Times : 0:00:08 0:00:00 0:00:00 0:00:08
   Ended : Friday, January 22, 2021 10:56:34 AM

[2021-01-22T10:56:34.4067462-05:00] DONE
[2021-01-22T10:56:56.1825927-05:00] MIRRORING LAUNCHBOX TO MEDIAVAULT

               Total Copied Skipped Mismatch FAILED Extras
    Dirs : 2098 0 2098 0 0 0
   Files : 2402 1 2401 0 0 0
   Bytes : 62.925 g 0 62.925 g 0 0 0
   Times : 0:00:08 0:00:00 0:00:00 0:00:08
   Ended : Friday, January 22, 2021 10:57:04 AM

[2021-01-22T10:57:04.5780894-05:00] DONE

```
### next steps

- send request to a healthchecks endpoint to register success (or failure)
- maybe integrate ntfy + pushover for push notifications
- or us smtp to send confirmations