Backup via SSH?

General support for the Pi-Star System
Post Reply
n9mxq
Posts: 236
Joined: Sun Apr 29, 2018 12:12 pm

Backup via SSH?

Post by n9mxq »

Hi Gang,

Is there a way to backup via SSH? I have one hotspot that's decided the NGNIX server needed a vacation, and I can't access via HTTP.. Is there a way to backup my settings via SSH?

Thanks.
Gene in Belvidere IL
Please don't email me with questions.
That's what these forums are for.
There's much more brainpower collected here
than I have alone.
KN2TOD
Posts: 264
Joined: Sun Nov 11, 2018 6:36 pm

Re: Backup via SSH?

Post by KN2TOD »

I'm assuming you plan on backing up your configuration and then restoring with a new image, correct?

But before doing that, let's see what wrong with your existing system. What results do you get when you run the following?

Code: Select all

sudo systemctl status nginx.service
sudo systemctl status php7.0-fpm.service
cat /var/log/nginx/error.log
(might want to boot your system first before running these commands so the resulting messages are current and haven't yet been rotated off.)

Also, have you run a successful system update/upgrade recently?

Code: Select all

rpi-rw
sudo apt update
sudo apt upgrade
rpi-ro
n9mxq
Posts: 236
Joined: Sun Apr 29, 2018 12:12 pm

Re: Backup via SSH?

Post by n9mxq »

Thanks for the tips.. here's what I see. As far as I can tell, nothing looks.. wonky...

Code: Select all

pi-star@pi-star3(ro):~$ sudo systemctl status nginx.service
● nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/etc/systemd/system/nginx.service; enabled; vendor preset: en
   Active: active (running) since Sun 2022-09-11 06:39:31 CDT; 5 days ago
     Docs: man:nginx(8)
  Process: 721 ExecStartPre=/bin/mkdir -p /var/log/nginx (code=exited, status=0/
  Process: 970 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process o
  Process: 1238 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code
 Main PID: 1239 (nginx)
    Tasks: 5 (limit: 2178)
   CGroup: /system.slice/nginx.service
           ├─1239 nginx: master process /usr/sbin/nginx -g daemon on; master_pro
           ├─1240 nginx: worker process
           ├─1241 nginx: worker process
           ├─1242 nginx: worker process
           └─1243 nginx: worker process

Warning: Journal has been rotated since unit was started. Log output is incomple
lines 1-17/17 (END)...skipping...
and then....

Code: Select all

pi-star@pi-star3(ro):~$ sudo systemctl status php7.0-fpm.service
● php7.0-fpm.service - The PHP 7.0 FastCGI Process Manager
   Loaded: loaded (/lib/systemd/system/php7.0-fpm.service; enabled; vendor preset: enabled)
   Active: failed (Result: timeout) since Sun 2022-09-11 06:39:10 CDT; 5 days ago
     Docs: man:php-fpm7.0(8)
  Process: 804 ExecStart=/usr/sbin/php-fpm7.0 --nodaemonize --fpm-config /etc/php/7.0/fpm/php-fpm.conf
 Main PID: 804 (code=killed, signal=TERM)

Warning: Journal has been rotated since unit was started. Log output is incomplete or unavailable.
lines 1-8/8 (END)
Logs returns:

Code: Select all

pi-star@pi-star3(ro):~$ cat /var/log/nginx/error.log

2022/09/17 04:28:21 [crit] 1240#1240: *13 connect() to unix:/var/run/php/php7.0-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 192.168.1.176, server: , request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php7.0-fpm.sock:", host: "192.168.1.154"
pi-star@pi-star3(ro):~$
Gene in Belvidere IL
Please don't email me with questions.
That's what these forums are for.
There's much more brainpower collected here
than I have alone.
KN2TOD
Posts: 264
Joined: Sun Nov 11, 2018 6:36 pm

Re: Backup via SSH?

Post by KN2TOD »

FPM (Fast CGI Process Manager) does NOT look normal: it should not be in a "failed" state. (Out of curiosity, when's the last time you booted?)

So, if a reboot doesn't clear this up, then my guess is that a config file or link for FPM is corrupted; a reinstall may fix that but that's an iffy proposition - all installs are not created equal.

We can dig a little deeper, if you want; try running this and see if we can get a hint as to what's wrong with FPM:

Code: Select all

sudo systemctl restart php7.0-fpm.service
sudo systemctl status php7.0-fpm.service
sudo cat /var/log/php7.0-fpm.log
----

But, if you just want to quickly move along, then run this to back up your config (and manually copy the resulting .zip file out of the /tmp directory) and then proceed on to rebuilding your system:

Code: Select all

#!/bin/bash
# backup Pi-Star configuration files from SSH command line
#
backupDir='/tmp/config_backup'
#
sudo rm -rf $backupDir 2>&1
sudo mkdir $backupDir 2>&1
if (cat /etc/dhcpcd.conf | grep "static ip_address" | grep -v "#"); then
  sudo cp /etc/dhcpcd.conf $backupDir 2>&1
fi
sudo cp /etc/wpa_supplicant/wpa_supplicant.conf $backupDir 2>&1
sudo cp /etc/ircddbgateway $backupDir 2>&1
sudo cp /etc/mmdvmhost $backupDir 2>&1
sudo cp /etc/dstarrepeater $backupDir 2>&1
sudo cp /etc/dapnetgateway $backupDir 2>&1
sudo cp /etc/p25gateway $backupDir 2>&1
sudo cp /etc/ysfgateway $backupDir 2>&1
sudo cp /etc/nxdngateway $backupDir 2>&1
sudo cp /etc/ysf2dmr $backupDir 2>&1
sudo cp /etc/dmrgateway $backupDir 2>&1
sudo cp /etc/mobilegps $backupDir 2>&1
sudo cp /etc/starnetserver $backupDir 2>&1
sudo cp /etc/timeserver $backupDir 2>&1
sudo cp /etc/dstar-radio.* $backupDir 2>&1
sudo cp /etc/crontab $backupDir 2>&1
sudo cp /etc/pistar-remote $backupDir 2>&1
sudo cp /etc/pistar-css.ini $backupDir 2>&1
sudo cp /etc/hosts $backupDir 2>&1
sudo cp /etc/hostname $backupDir 2>&1
sudo cp /etc/bmapi.key $backupDir 2>&1
sudo cp /etc/dapnetapi.key $backupDir 2>&1
sudo cp /usr/local/etc/RSSI.dat $backupDir 2>&1
sudo cp /var/www/dashboard/config/ircddblocal.php $backupDir 2>&1
sudo cp /var/www/dashboard/config/config.php $backupDir 2>&1
#
sudo mkdir $backupDir/Extra 2>&1
sudo cp /etc/iptables.rules $backupDir/Extra 2>&1
sudo cp /etc/ip6tables.rules $backupDir/Extra 2>&1
sudo cp /etc/rc.local $backupDir/Extra 2>&1
#
hostNameInfo=$(cat /etc/hostname)
hostNameInfo=${hostNameInfo^^}
local_time=$(date +%m-%d-%y-%H%M%S)
zipfile=$hostNameInfo-Config-$local_time.zip
sudo zip -j /tmp/$zipfile $backupDir/* 2>&1
unzip -l /tmp/$zipfile 2>&1
User avatar
YL3IM
Posts: 39
Joined: Sun Nov 22, 2020 8:38 pm
Location: Riga, Latvia
Contact:

Re: Backup via SSH?

Post by YL3IM »

Code: Select all

mkdir -p /tmp/pi-backup

rsync -xav --delete-before pi-star@YOURPISTARIP:/etc/wpa_supplicant/wpa_supplicant.conf :/etc/ircddbgateway :/etc/mmdvmhost :/etc/dstarrepeater :/etc/dapnetgateway :/etc/p25gateway :/etc/ysfgateway :/etc/ysf2dmr :/etc/dgidgateway :/etc/nxdngateway :/etc/dmrgateway :/etc/mobilegps :/etc/starnetserver :/etc/timeserver :/etc/dstar-radio.* :/etc/pistar-remote :/etc/hosts :/etc/hostname :/etc/bmapi.key :/etc/dapnetapi.key :/etc/pistar-css.ini :/usr/local/etc/RSSI.dat :/var/www/dashboard/config/ircddblocal.php :/var/www/dashboard/config/config.php /tmp/pi-backup

zip -j Pi-Star_Config_pi-star_`date +%Y-%b-%d`.zip /tmp/pi-backup/*
n9mxq
Posts: 236
Joined: Sun Apr 29, 2018 12:12 pm

Re: Backup via SSH?

Post by n9mxq »

Well, now I have bigger problems than just the web server.. the PI is no longer powering the hat... So, who knows...

Thanks for the tips...
Gene in Belvidere IL
Please don't email me with questions.
That's what these forums are for.
There's much more brainpower collected here
than I have alone.
Post Reply