Skip to content

Instantly share code, notes, and snippets.

@ZSendokame
Created December 26, 2024 21:36
Show Gist options
  • Select an option

  • Save ZSendokame/8b2f58c4b11b9d3d69abacb95cd72bc3 to your computer and use it in GitHub Desktop.

Select an option

Save ZSendokame/8b2f58c4b11b9d3d69abacb95cd72bc3 to your computer and use it in GitHub Desktop.
The simplest backup script for personal uses, feel free to modify.
# WARNINGS AND WORKINGS:
# The script can be downloaded anywhere, but if there is no folder named as defined in $backupFolder, then it will create it.
# BEFORE running the script, add the folders to backup in the $folders array.
# To execute backup.ps1, calling it from a PowerShell session is enough (.\backup.ps1).
# Useful variables to modify and/or use.
$backupFolder = ".\backup"
$desktop = [Environment]::GetFolderPath("Desktop")
$folders = @()
# File matching, feel free to add or modify.
$files = foreach($folder in $folders) {
(Get-ChildItem "$folder/*.json").FullName
}
if(-not (Test-Path $backupFolder)) {
New-Item -ItemType Directory -Path $backupFolder
}
foreach($file in $files) {
$itemName = (Get-Item $file).Name
Copy-Item -Path $file -Destination "$backupFolder\$itemName"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment