Skip to content

Instantly share code, notes, and snippets.

@cptpiepmatz
Created September 12, 2023 08:53
Show Gist options
  • Save cptpiepmatz/c8f32f223c74708a18dfeb3bc9bbdc4c to your computer and use it in GitHub Desktop.
Save cptpiepmatz/c8f32f223c74708a18dfeb3bc9bbdc4c to your computer and use it in GitHub Desktop.
Backup Monster Hunter Rise Steam Save Games
#!/usr/bin/env nu
# Constants
const STEAM_DIR = 'steam/dir'
const USER_ID = 'userid'
const TARGET_DIR = 'target/dir'
# Function to get the current date
def get-date [] {
date now | format date '%Y-%m-%d'
}
# Function to check if a file exists
def file-exists [path] {
ls ($path | path dirname) | where name =~ ($path | path basename) | length | $in > 0
}
# Function to get the next available backup filename
def get-next-backup-filename [] {
mut idx = 0
let current_date = (get-date)
mut filename = $TARGET_DIR + '/MHR-' + $current_date + '.' + ($idx | to text) + '.bak.zip'
while (file-exists $filename) {
$idx = $idx + 1
$filename = $TARGET_DIR + '/MHR-' + $current_date + '.' + ($idx | to text) + '.bak.zip'
}
echo $filename
}
# Main script
let save_dir = $STEAM_DIR + '/userdata/' + $USER_ID + '/1446780/remote/win64_save'
let backup_filename = (get-next-backup-filename)
# Compress the directory using ouch
ouch compress $save_dir $backup_filename -f zip -y
echo ('Backup saved to: ' + $backup_filename)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment