Skip to content

Instantly share code, notes, and snippets.

@Vitexus
Created November 24, 2016 22:59
Show Gist options
  • Save Vitexus/f0dc38f5afd233dbd34bb65d6455ec94 to your computer and use it in GitHub Desktop.
Save Vitexus/f0dc38f5afd233dbd34bb65d6455ec94 to your computer and use it in GitHub Desktop.
Make backup for given host's /etc/ by one command ( by using BackupPC )
#!/bin/bash
#1) Ask for host
if [ -z $1 ];
then
echo -n "Host to backup and press [ENTER]: "
read sourcehost
else
sourcehost=$1
fi
#2) If host is unknown create configuration
if [ `sudo grep "^$1\s" "/etc/backuppc/hosts" | wc -l` -ne "1" ];
then
echo "$sourcehost 0 backuppc vitex" | sudo -u backuppc tee --append /etc/backuppc/hosts > /dev/null
echo "\$Conf{RsyncShareName} = [ '/etc' ]; " | sudo -u backuppc tee --append "/etc/backuppc/$sourcehost.pl" > /dev/null
sudo service backuppc restart
if [ -z $(sudo -u backuppc ssh $sourcehost 'which rsync') ];
then
echo NO RSYNC on $sourcehost
ssh $sourcehost 'DEBIAN_FRONTEND=noninteractive apt-get -y install rsync'
fi
fi
#3) Sync /etc
curl -s "http://backuppc:HTPASSWORD@localhost/backuppc/index.cgi?host=$sourcehost&hostIP=$sourcehost&doit=1&action=Start_Full_Backup" | grep "Reply from server"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment