Last active
May 9, 2024 09:03
-
-
Save Wind010/f3f2b67fcd26ba5a742f9a4c5bb4b274 to your computer and use it in GitHub Desktop.
Powershell scripts to backup and restore a pwnagotchi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Script to backup your pwnagotchi. | |
# Usage: | |
# backup_pwnagotchi.ps1 <ip_address_of_pwnagotchi> | |
# The <ip_address_of_pwnagotchi> should be the static ip address set previously (10.0.0.2). | |
# Can setup SSH keys to bypass password prompt for SCP. | |
param( | |
[Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$false)] | |
[string] | |
$ip | |
) | |
Write-Host "Backing up PWNAGOTCHI" | |
$date = Get-Date -UFormat '%Y%m%dT%H%M%S' | |
$tarFileName = "PWNAGOTCHI-BAK-${date}.tar.gz" | |
$tmpPath = './tmp' | |
$configPath = "$tmpPath/pwnagotchi" | |
$rootPath = "$tmpPath/root" | |
Remove-Item $tmpPath -Recurse -Force 2> $null | |
$ErrorActionPreference = "Stop" | |
New-Item -Path $tmpPath -ItemType Directory | |
New-Item -Path $configPath -ItemType Directory | |
Write-Host "Backup keys and configuration..." | |
scp root@${ip}:/etc/pwnagotchi/* $configPath | |
Write-Host "Backup root recursively..." | |
scp -r root@${ip}:/root $tmpPath | |
# Remove uneeded folders after the fact rather than explicit scp for files/folders. | |
Remove-Item $rootPath/.ansible -Recurse -Force | |
Remove-Item $rootPath/.gnupg -Recurse -Force | |
Remove-Item $rootPath/.keras -Recurse -Force | |
Remove-Item $rootPath/.cache -Recurse -Force | |
Remove-Item $rootPath/.config -Recurse -Force | |
Remove-Item $rootPath/.local -Recurse -Force | |
cd $tmpPath | |
Write-Host "Archiving to $tarFileName..." | |
tar -zcvf $tarFileName . | |
Copy-Item *.gz .. | |
cd .. | |
Remove-Item $tmpPath -Recurse -Force |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Script to restore your pwnagotchi. | |
# Usage: | |
# backup_pwnagotchi.ps1 <ip_address_of_pwnagotchi> <archive_to_restore_path> | |
# The <ip_address_of_pwnagotchi> should be the static ip address set previously (10.0.0.2). | |
# The <archive_to_restore_path> is the tar/gzip file to restore. | |
# Can setup SSH keys to bypass password prompt for SCP. | |
param( | |
[Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$false)] | |
[string] | |
$ip, | |
[Parameter(Mandatory=$true, Position=1, ValueFromPipeline=$false)] | |
[string] | |
$archivePath | |
) | |
Write-Host "Restoring PWNAGOTCHI" | |
$date = Get-Date -UFormat '%Y%m%dT%H%M%S' | |
$tmpPath = './tmp' | |
$configPath = "$tmpPath/pwnagotchi" | |
$rootPath = "$tmpPath/root" | |
Remove-Item $tmpPath -Recurse -Force 2> $null | |
$ErrorActionPreference = "Stop" | |
New-Item -Path $tmpPath -ItemType Directory | |
Write-Host "Extracting $archivePath to $tmpPath" | |
tar -xvzf $archivePath -C $tmpPath | |
Write-Host "Restoring keys and configuration..." | |
scp -r $configPath/* root@${ip}:/etc/pwnagotchi | |
Write-Host "Restoring root..." | |
scp -r $rootPath/* root@${ip}:/root | |
Remove-Item $tmpPath -Recurse -Force |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment