Easily back up and restore your PuTTY sessions using a PowerShell script or a portable EXE
EXE Version: The EXE was generated by packaging the PowerShell script. It's 100% the same logicโopen source and transparent.
Open Source: This tool is fully open source. Feel free to read, modify, and redistribute the script.
Compatibility: Works with all versions of PuTTY and supports Windows 7+ and PowerShell 3.0+.
๏ปฟ##
## Putty Backup Tool.
## Nader Barakat 2022 - Aug
##################################################
##################################################
## MENU
function Connect-Menu
{
param (
[string]$Title = 'Putty SSH info saved in Win-Registry'
)
Clear-Host
Write-Host " " -ForegroundColor Yellow
Write-Host "`n Putty SSH Easy Backup Script: " -ForegroundColor Yellow
Write-Host " By Nader Barakat - 2022" -ForegroundColor Yellow
Write-Host " Email: naderb@naderb.org - 2022" -ForegroundColor Yellow
Write-Host " https://www.naderb.org " -ForegroundColor Yellow
Write-Host " " -ForegroundColor Yellow
VER-Check
Write-Host "================ $Title ================" -ForegroundColor Green
Write-Host " " -ForegroundColor Yellow
Write-Host " Press 'B' To Backup" -ForegroundColor Yellow
Write-Host " Press 'L' To List Backup Files" -ForegroundColor Yellow
Write-Host " Press 'O' To Open Backup Folder with windows Explorer" -ForegroundColor Yellow
Write-Host " Press 'D' To Delete Old Backup" -ForegroundColor Yellow
Write-Host " Press 'R' To Restore from backup folder" -ForegroundColor Yellow
Write-Host " Press 'A' To Restore from backup folder" -ForegroundColor Yellow
Write-Host " Press 'Q' to quit (Exit this program)." -ForegroundColor RED
Write-Host " " -ForegroundColor Yellow
Write-Host "======================================================================" -ForegroundColor Green
Write-Host " " -ForegroundColor Yellow
}
##################################################
# Main Menu Selector.
#
function MAINMENU {
$input = Read-Host "Please make a selection"
switch ($input)
{
'B' {
JOB("Backup")
Break
}
'L' {
JOB("List")
Break
}
'o' {
JOB("Open")
Break
}
'D' {
JOB("Delete")
Break
}
'R' {
JOB("Restore")
Break
}
'A' {
JOB("About")
Break
}
'q' {
return
}
}
}
##################################################
# to check if there is a new version of the script.
# its goes online to read the version number. if not the same. there is a newer version.
#
#
function VER-Check {
$SCRIPTVERSION="0.01"
#Use the supported TLS version
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$url = "https://www.naderb.org/puttybackup/version.php"
$UPDATE=echo (new-object Net.WebClient).DownloadString("$url") | IEX 2>$null
if ( $SCRIPTVERSION -eq $UPDATE ) {
write-host "Software up to date." -ForegroundColor Green
Write-host " Script Run Path: $PSScriptRoot" -ForegroundColor White
} else {
write-host "New version Available: $UPDATE " -ForegroundColor Yellow
Write-host "Download URL: https://www.naderb.org/puttybackup/" -ForegroundColor Green
write-host "current Version :$SCRIPTVERSION " -ForegroundColor green
}
}
##################################################
# Check path or file if available function !
function DPATHCHECK($FFPATH) {
Write-Host "`n **Function: $FFPATH " -ForegroundColor White
Write-Host " ChecK Path function Started: " -ForegroundColor DarkYellow
if (Test-Path -Path $FFPATH) {
## found
Write-Host " -found $FFPATH" -ForegroundColor DarkGreen
Write-Host " STATUS: "-ForegroundColor Yellow -NoNewline;
Write-Host "[ "-ForegroundColor Yellow -NoNewline;
Write-Host " Found " -ForegroundColor Green -NoNewline;
Write-Host "] `n"-ForegroundColor Yellow
Return 1
} else {
## Not Found
Write-Host " -Not found $FFPATH" -ForegroundColor DarkRed
Write-Host " STATUS: "-ForegroundColor Yellow -NoNewline;
Write-Host "[ "-ForegroundColor Yellow -NoNewline;
Write-Host " Not Found " -ForegroundColor darkred -NoNewline;
Write-Host "] `n"-ForegroundColor Yellow
return 0
}
}
###################################################
# Do the Job Switch Function
#
###################################################
function JOB($ENGNAME1)
{
cls
# Find Mydocumens in my profile:
$FPath= [Environment]::GetFolderPath("MyDocuments")
# Backup folder inside Mydocuments
$BACKUPPATH ="$FPath\PuttyBackup"
switch ($ENGNAME1)
{
'Backup' {
Write-Host "================ Checking Backup Folder ================" -ForegroundColor Green
Write-Host "BACKUPPATH set to: $BACKUPPATH" -ForegroundColor Yellow
$FOLDERAV = DPATHCHECK("$BACKUPPATH")
if ( $FOLDERAV -eq "1" ) {
Write-Host "Backup Path Found : $BACKUPPATH `n" -ForegroundColor Yellow
} else {
Write-Host "Backup folder not available, it will be created." -ForegroundColor Yellow
New-Item "$BACKUPPATH" -itemType Directory
$FOLDERAV=DPATHCHECK("$BACKUPPATH")
if ( $FOLDERAV -eq "0" ) {
Write-Host "ERROR, Can't Create Backup folder path:BACKUPPATH " -ForegroundColor red
Break
}
Write-Host "Backup Path Created : $BACKUPPATH `n" -ForegroundColor Yellow
}
## Name of the files to backup
$FULLFPATH="$BACKUPPATH\Putty $(get-date -f dd-MM-yyyy--HH-mm).reg"
$SESSIONSFULLFPATH="$BACKUPPATH\Putty-sessions $(get-date -f dd-MM-yyyy--HH-mm).reg"
reg export HKCU\Software\SimonTatham $FULLFPATH /y
reg export HKCU\Software\SimonTatham\PuTTY\Sessions $SESSIONSFULLFPATH /y
Write-Host "Data writen to : $FULLFPATH" -ForegroundColor Yellow
Write-Host "Session Data writen to : $SESSIONSFULLFPATH" -ForegroundColor Yellow
Write-Host "========================================================" -ForegroundColor Green
Write-Host "Back to Main Menu." -ForegroundColor DarkYellow
pause
Connect-Menu
MAINMENU
}
'List' {
ls $BACKUPPATH
Write-Host " " -ForegroundColor DarkYellow
Write-Host "Back to Main Menu." -ForegroundColor DarkYellow
pause
Connect-Menu
MAINMENU
}
'Open' {
Invoke-Item $BACKUPPATH
Write-Host " " -ForegroundColor DarkYellow
Write-Host "Back to Main Menu." -ForegroundColor DarkYellow
Connect-Menu
MAINMENU
}
'Restore' {
Write-Host "Just Double click on the file you want to restore." -ForegroundColor DarkYellow
Invoke-Item $BACKUPPATH
Write-Host " " -ForegroundColor DarkYellow
Write-Host "Back to Main Menu." -ForegroundColor DarkYellow
Connect-Menu
MAINMENU
}
'Delete' {
Write-Host "Delete files older than 3 days." -ForegroundColor DarkYellow
$confirm = Read-Host "Are You sure you want to delete older backup files ? Y/N "
switch ($confirm)
{
'Y' {
Get-ChildItem $BACKUPPATH -Recurse -File | Where CreationTime -lt (Get-Date).AddDays(-3) | Remove-Item -Force
ls $BACKUPPATH
Break
}
'N' {
Connect-Menu
MAINMENU
}
}
Get-ChildItem $BACKUPPATH -Recurse -File | Where CreationTime -lt (Get-Date).AddDays(-3) | Remove-Item -Force
Write-Host " " -ForegroundColor DarkYellow
Write-Host "Back to Main Menu." -ForegroundColor DarkYellow
pause
Connect-Menu
MAINMENU
}
'About' {
Write-Host " Created by: Nader Barakat " -ForegroundColor Yellow
Write-Host " Email: naderb@naderb.org " -ForegroundColor Yellow
Write-Host " Modified: Aug-2022 " -ForegroundColor Yellow
pause
Connect-Menu
MAINMENU
}
}
return
}
##################################################
# Start
# Run the functions.
#
Connect-Menu
MAINMENU
#
#
##################################################EOF