Last active
September 11, 2025 08:03
-
-
Save corny/3cf7af0f6cb7a00adeb3 to your computer and use it in GitHub Desktop.
Revisions
-
corny revised this gist
Mar 29, 2015 . 1 changed file with 5 additions and 6 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -20,16 +20,13 @@ mkdir -p $output curl_cmd="curl --cookie /tmp/cookie --cookie-jar /tmp/cookie --insecure --silent --fail" # authenticate against unifi controller if ! $curl_cmd --data '{"username":"'$username'","password":"'$password'"}' $baseurl/api/login > /dev/null; then echo Login failed exit 1 fi # ask controller to do a backup, response contains the path to the backup file path=`$curl_cmd --data 'json={"cmd":"backup","days":"-1"}' $baseurl/api/s/default/cmd/system | sed -n 's/.*\(\/dl.*unf\).*/\1/p'` # download the backup to the destinated output file $curl_cmd $baseurl$path -o $output/$filename @@ -39,3 +36,5 @@ $curl_cmd $baseurl/logout # delete outdated backups find $output -ctime +$keep_days -type f -delete echo Backup successful -
corny revised this gist
Jan 17, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -37,5 +37,5 @@ $curl_cmd $baseurl$path -o $output/$filename # logout $curl_cmd $baseurl/logout # delete outdated backups find $output -ctime +$keep_days -type f -delete -
corny revised this gist
Jan 17, 2015 . 1 changed file with 5 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -12,14 +12,17 @@ source ~/.unifi-backup baseurl=https://localhost:8443 output=/root/backups/unifi filename=`date +%Y%m%d%H%M`.unf keep_days=1 # create output directory mkdir -p $output curl_cmd="curl --cookie /tmp/cookie --cookie-jar /tmp/cookie --insecure --silent --fail" # authenticate against unifi controller result=`$curl_cmd --data "login=login" --data "username=$username" --data "password=$password" $baseurl/login -v 2>&1 | grep "HTTP/1.1 302 Found" || true` # successfully authenticated? if [ -z "$result" ]; then echo login failed exit 1 @@ -34,5 +37,5 @@ $curl_cmd $baseurl$path -o $output/$filename # logout $curl_cmd $baseurl/logout # Delete outdated backups find $output -ctime +$keep_days -type f -delete -
corny created this gist
Jan 17, 2015 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,38 @@ #!/bin/bash -e # # Improved backup script for Ubiquiti UniFi controller # original source: http://wiki.ubnt.com/UniFi#Automated_Backup # # must contain: # username=<username> # password=<password> source ~/.unifi-backup baseurl=https://localhost:8443 output=/root/backups/unifi filename=`date +%Y%m%d%H%M`.unf mkdir -p $output curl_cmd="curl --cookie /tmp/cookie --cookie-jar /tmp/cookie --insecure --silent --fail" # authenticate against unifi controller result=`$curl_cmd --data "login=login" --data "username=$username" --data "password=$password" $baseurl/login -v 2>&1 | grep "HTTP/1.1 302 Found" || true` if [ -z "$result" ]; then echo login failed exit 1 fi # ask controller to do a backup, response contains the path to the backup file path=`$curl_cmd --data 'json={"cmd":"backup"}' $baseurl/api/cmd/system | sed -n 's/.*\(\/dl.*unf\).*/\1/p'` # download the backup to the destinated output file $curl_cmd $baseurl$path -o $output/$filename # logout $curl_cmd $baseurl/logout # Backups löschen, die älter als 24 Stunden sind find $output -ctime +1 -type f -delete