Hi I need help with my SH files please. Its for Rsync command to backup my files to other vps but it seems its not working not really sure why.
First File.
GENKEYS.SH (run on main server)
So what I do is run this file on the old or main server.
2nd File.
SETKEYS.SH (run on backup server)
3rd file
Sync.sh (Will be run on Main server)
I think I manage to run this but It seems its not updating files on the backup server, maybe it wasn't overwriting existing files?
PLease help.!
First File.
GENKEYS.SH (run on main server)
Code:
#!/bin/bashcd /etc
chmod 777 *.sh
echo "Done: setting chmod 777 *.sh ..."
mkdir /root/.ssh
rm -f /root/.ssh/id*
rm -f /etc/destinationetc/.ssh/authorized*
rm -f /root/.ssh/known_hosts
echo "deleted existing keys...."
echo "SOURCESERVER will create the public/private key pair to be used for authentication."
echo " ***********************************************************************"
echo ""
echo "*Note: Do not enter a passphrase for this, just hit ENTER when prompted."
echo "*Note: Do not enter a passphrase for this, just hit ENTER when prompted."
echo "*Note: Do not enter a passphrase for this, just hit ENTER when prompted."
echo "*Note: Do not enter a passphrase for this, just hit ENTER when prompted."
echo "*Note: Do not enter a passphrase for this, just hit ENTER when prompted."
echo "*Note: Do not enter a passphrase for this, just hit ENTER when prompted."
echo ""
echo " ***********************************************************************"
ssh-keygen -t rsa
echo "DONE: SOURCESERVER created the public/private key pair @ /root/.ssh/id_rsa.pub and /root/.ssh/id_rsa.pub"
echo " ***********************************************************************"
rm -f /etc/destinationetc/.ssh/id_rsa.pub
rm -f /etc/destinationetc/.ssh/authorized_keys
echo ""
echo "deleted existing keys...."
echo ""
cp -r /root/.ssh/id_rsa.pub /etc/destinationetc/.ssh
cd /etc/destinationetc/.ssh
mv id_rsa.pub authorized_keys
echo "DONE: Generated fresh authorized_keys file to "
echo "/etc/destinationetc/ ..."
echo ""
echo " ***********************************************************************"
echo ""
echo "DO NOT forget to edit the file "
echo " /etc/destinationetc/.ssh/authorized_keys ..."
echo "at Main Server before deploying to other server....."
echo "...look for root@domain.com and then edit it into"
echo " root@64.xxx.xxx.81 format ..."
echo ""
echo ""
echo " ***********************************************************************"
echo ""
cat /etc/destinationetc/.ssh/authorized_keys
echo ""
echo " ***********************************************************************"
echo "Done.........."
echo "Done.........."
So what I do is run this file on the old or main server.
2nd File.
SETKEYS.SH (run on backup server)
Code:
#!/bin/bash
cd /etc
chmod 777 *.sh
echo "Done: setting chmod 777 *.sh ..."
mkdir /root/.ssh
echo "Done: mkdir /root/.ssh"
cp -r /etc/.ssh/authorized_keys /root/.ssh
echo "Done: cp -r /etc/.ssh/authorized_keys /root/.ssh"
cd /root
chmod 600 .ssh
cd .ssh
chmod 700 authorized_keys
cd /etc
cp -r /etc/sshd_config /etc/ssh
echo "Done: cp -r /etc/sshd_config /etc/ssh"
mkdir /etc/openvpn/logs
echo "Done: mkdir /etc/openvpn/logs"
cp -r /etc/logs/server*.log /etc/openvpn/logs
echo "Done: cp -r /etc/logs/server*.log /etc/openvpn/logs"
echo "Done: /etc/setkeys.sh"
/etc/init.d/sshd stop
echo "Done: /etc/init.d/sshd stop"
/etc/init.d/sshd start
echo "Done: /etc/init.d/sshd start"
/etc/init.d/sshd restart
echo "Done: /etc/init.d/sshd restart"
echo "Done.........."
echo "Done.........."
echo "Done.........."
echo "Done.........."
3rd file
Sync.sh (Will be run on Main server)
Code:
#!/bin/bash
echo "Main Server xx.xxx.xxx.xx....Source of updated files....."
echo "..................................................................."
echo "..................................................................."
echo "Backup server..........................................................."
echo "VPS xx.xx.xxx.xx Starting to sync accounts......................"
rsync -a -e ssh /etc/passwd root@xx.xx.xxx.xx:/etc/passwd
rsync -a -e ssh /etc/passwd- root@xx.xx.xxx.xx:/etc/passwd-
rsync -a -e ssh /etc/group root@xx.xx.xxx.xx:/etc/group
rsync -a -e ssh /etc/group- root@xx.xx.xxx.xx:/etc/group-
rsync -a -e ssh /etc/shadow root@xx.xx.xxx.xx:/etc/shadow
rsync -a -e ssh /etc/shadow- root@xx.xx.xxx.xx:/etc/shadow-
echo "VPS xx.xx.xxx.xx Done syncing accounts.........................."
I think I manage to run this but It seems its not updating files on the backup server, maybe it wasn't overwriting existing files?
PLease help.!