Restore Script Keeps asking for password.

Status
Not open for further replies.

Andyd358

Member
Aug 23, 2018
243
8
18
55
UK
Hi I have thsi script (Copied from this forum)

When I run it to test on a new install it keeps asking for the rooot password. How do I avoid this either tell the script where the password is or tell it what it is. So that I can run this as a daily cron at night.


#!/bin/sh
now=$(date +%Y-%m-%d)
ssh_server=xxx.xxx.xxx.xxx
database_host=127.0.0.1
database_port=5432
export PGPASSWORD="XXXXXXXXXXXXXXXXXXXXX"

#run the remote backup
ssh -p 22 root@$ssh_server "nice -n -20 /etc/cron.daily/./backup-daily.sh"

#delete freeswitch logs older 7 days
find /var/log/freeswitch/freeswitch.log.* -mtime +7 -exec rm {} \;

#synchronize the backup directory
#rsync -avz -e 'ssh -p 22' root@$ssh_server:/var/backups/fusionpbx /var/backups
rsync -avz -e 'ssh -p 22' root@$ssh_server:/var/backups/fusionpbx/postgresql /var/backups/fusionpbx
rsync -avz -e 'ssh -p 22' root@$ssh_server:/var/www/fusionpbx /var/www
rsync -avz -e 'ssh -p 22' root@$ssh_server:/etc/fusionpbx /etc
find /var/backups/fusionpbx/postgresql -mtime +2 -exec rm {} \;

rsync -avz -e 'ssh -p 22' root@$ssh_server:/etc/freeswitch/ /etc
rsync -avz -e 'ssh -p 22' root@$ssh_server:/var/lib/freeswitch/storage /var/lib/freeswitch
rsync -avz -e 'ssh -p 22' root@$ssh_server:/var/lib/freeswitch/recordings /var/lib/freeswitch
rsync -avz -e 'ssh -p 22' root@$ssh_server:/usr/share/freeswitch/scripts /usr/share/freeswitch
rsync -avz -e 'ssh -p 22' root@$ssh_server:/usr/share/freeswitch/sounds /usr/share/freeswitch

echo "Restoring the Backup"
#extract the backup from the tgz file
#tar -xvpzf /var/backups/fusionpbx/backup_$now.tgz -C /

#remove the old database
psql --host=$database_host --port=$database_port --username=fusionpbx -c 'drop schema public cascade;'
psql --host=$database_host --port=$database_port --username=fusionpbx -c 'create schema public;'
#restore the database
pg_restore -v -Fc --host=$database_host --port=$database_port --dbname=fusionpbx --username=fusionpbx /var/backups/fusionpbx/postgresql/fusionpbx_pgsql_$now.sql

#restart freeswitch
service freeswitch restart
echo "Restore Complete";
 

ad5ou

Active Member
Jun 12, 2018
884
197
43
It's fairly simple process. That doc spells it out well.
generate key on server. copy to new server
 
  • Like
Reactions: Andyd358

Adrian Fretwell

Well-Known Member
Aug 13, 2017
1,414
376
83
SSH key based authentication is undoubtedly the best way of doing this, I use it myself. Just for completeness, there is another option, and I do not recommend it. There is a utility called sshpass (On Debian: apt-get install sshpass), this allows you to embed the ssh password in the script. As I say, I don't recommend it but it can be useful when, for whatever reason, you cannot install your public key on a given server. An example using SFTP shown below:

Code:
#!/bin/bash

export SSHPASS=xxxxxxxxxxxxxxxx

sshpass -e sftp -oBatchMode=no -b - user@server.co.uk << !
   cd /some-directory
   get myfile.txt
   bye
!

exit 0
 
  • Like
Reactions: Andyd358

Andyd358

Member
Aug 23, 2018
243
8
18
55
UK
SSH key based authentication is undoubtedly the best way of doing this, I use it myself. Just for completeness, there is another option, and I do not recommend it. There is a utility called sshpass (On Debian: apt-get install sshpass), this allows you to embed the ssh password in the script. As I say, I don't recommend it but it can be useful when, for whatever reason, you cannot install your public key on a given server. An example using SFTP shown below:

Code:
#!/bin/bash

export SSHPASS=xxxxxxxxxxxxxxxx

sshpass -e sftp -oBatchMode=no -b - user@server.co.uk << !
   cd /some-directory
   get myfile.txt
   bye
!

exit 0
The SSH Key Was the way i went. Im not a linux person so didnt know about this but by god it was easy to setup.
 

ad5ou

Active Member
Jun 12, 2018
884
197
43
and now that you have a made a key, make yourself a new one for your usual ssh client and turn off password authentication all together for a more secure server :)
 

Andyd358

Member
Aug 23, 2018
243
8
18
55
UK
and now that you have a made a key, make yourself a new one for your usual ssh client and turn off password authentication all together for a more secure server :)
WHOA there big fella Ive only just learnt to walk lol :) Ill get around to that at some point hahahah
 
Status
Not open for further replies.