Skip to content

Instantly share code, notes, and snippets.

@instance-id
Last active November 3, 2020 00:20
Show Gist options
  • Save instance-id/3fae80427a75b61266301f843068dabf to your computer and use it in GitHub Desktop.
Save instance-id/3fae80427a75b61266301f843068dabf to your computer and use it in GitHub Desktop.
Unity project backup via RClone using Powershell ()
Param (
[Parameter()]
[string]$Project,
[Parameter()]
[string]$Source,
[Parameter()]
[switch]$Backup # <--
) # The items below parse the arguments passed in via the
$argument = $args[0] # <-- command line so that they can be used within the script
$configDir = "C:/Users/mosthated/.backup"
# ^ --- The location of your rclone configuration file
if (!$Project || !$Source) {
# Is the project name or project source path are missing, return message and do not continue
Write-Host "Parameter missing"
Return
}
else {
$date = Get-Date -Format "yyyy-MM-dd_HH-mm-ss" # Gets current date for filename and path purposes
$date2 = Get-Date -Format "yyyyMMddHHmmss" # Gets current date for filename and path purposes
$config = "--config=$configDir/rclone.conf"
# ^ --- Rclone configuration file
$filter = "--filter-from=C:\Users\mosthated\.backup\_projects\unity.fltr"
# ^ --- The location of the Unity specific filter file. This is like a .gitignore in that you can specify what files to, or to not backup.
$backupdir = "--backup-dir=HDrive:X:/_dev/_unity/_projects/.history/$Project/"
$suffix = "--suffix=$date2" # ^ Change this to where you want prior backup files to go, so you have a backup history.
# Suffix is appended to ^ $Project gets passed in when this is ran, but must remain at the end of the path.
# backup history items ^ If backup history is not important, remove the item below marked as ^&HISTORY^
$cmd = "C:\files\rclone\rclone.exe"
# # ^ The location of the rclone executable file
$source1 = "$Source"
# $destination1 = "pcbackup:/_backups/desktop-projects"
# $destination1 = "HDrive:H:/_unity/_projects/$Project/"
$destination1 = "HDrive:X:/_dev/_unity/_projects/_backup/$Project/"
# -------| ^ Change this to the location in which your backups will be saved. As with above,
# -------| ^ the $Project/ variable must remain at the end of the path
[string]$logPath = "C:\files\rclone\logs\"
# ---| ^ The location of the backup log files. If this path does not exist, it will be created.
if (!([System.IO.Directory]::Exists($logPath))) {
[system.io.directory]::CreateDirectory($logPath)
}
$log1 = "--log-file=C:\files\rclone\logs\unity_$Project_$date.log"
Write-Output "Project sync to HDrive"
if ($Backup) {
Write-Output "Backing up files"
&$cmd sync $source1 $destination1 $log1 $filter $config $backupdir $suffix --log-level NOTICE --progress --delete-during --no-update-modtime --drive-chunk-size 2048M --buffer-size 8192M --transfers=4 --checkers=4 --contimeout=60s --timeout=300s --retries=3 --low-level-retries=10 -L --stats=1s --stats-file-name-length=0 -P --ignore-case --fast-list
# ^&HISTORY^ ^&SUFFIX^
}
else {
Write-Output "Backing up files"
&$cmd sync $source1 $destination1 $log1 $filter $config --log-level NOTICE --progress --delete-during --no-update-modtime --drive-chunk-size 2048M --buffer-size 8192M --transfers=4 --checkers=4 --contimeout=60s --timeout=300s --retries=3 --low-level-retries=10 -L --stats=1s --stats-file-name-length=0 -P --ignore-case --fast-list
}
# New-BurntToastNotification -Silent -Text "Status Update:", # An OS notification toast message when the current backup is completed. This can be commented out, or removed.
Write-Output "Projects backup complete"
} # Don't fuck around with your data. When it's gone, it's gone. Backup now, backup often.
- Library/**
- _build/**
- obj/**
- Temp/**
- node_modules/**
# Put the Unity projects you want to back up in this list, then this is the file that you run to perform the backups.
# This script calls the main script and passes in the below data for each project you want to backup.
&C:\Users\***YOUR_USER_NAME***\.backup\_projects\projects_backup.ps1 -Project My_killer_game -Source E:\_unity\_projects\My_killer_game
&C:\Users\***YOUR_USER_NAME***\.backup\_projects\projects_backup.ps1 -Project My_other_killer_game -Source E:\_unity\_projects\My_other_killer_game
# ^-- Change to your username and location of ^-- Name of Project ^ Project source file location
# project_backup.ps1 and Unity.fltr file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment