#!/bin/bash
sudo mkdir -p /tmp/backup | sudo chown vunet:vunet /tmp/backup
sudo mkdir -p /tmp/backup/analyser1-backup | sudo chown vunet:vunet /tmp/backup/analyser1-backup
sudo mkdir -p /tmp/backup/analyser2-backup | sudo chown vunet:vunet /tmp/backup/analyser2-backup
echo “Copying the contents of analyser logstash folder in tmp”
ssh shipper2 “sudo chmod 755 -R /etc/logstash/ | scp -r /etc/logstash/ shipper:/tmp/backup/shipper2-backup”
ssh analyser “sudo chmod 755 -R /etc/logstash/ | scp -r /etc/logstash/ shipper:/tmp/backup/analyser1-backup”
ssh analyser2 “sudo chmod 755 -R /etc/logstash/ | scp -r /etc/logstash/ shipper:/tmp/backup/analyser2-backup”
echo “Copying contents of cairo,logstash,opt folder of shipper in tmp”
#sudo chmod 755 -R /home/vunet/workspace/cairo/ | sudo cp -r /home/vunet/workspace/cairo/ /tmp/backup/shipper-confbackup/
sudo chmod 755 -R /opt/data_config_store/ | sudo cp -r /opt/data_config_store/ /tmp/backup/shipper-confbackup/
sudo chmod 755 -R /etc/redis/ | sudo cp -r /etc/redis/ /tmp/backup/shipper-confbackup/
#sudo chmod 755 -R /opt/kibana/ | sudo cp -r /opt/kibana/ /tmp/backup/shipper-confbackup/
#sudo chmod 755 -R /var/www/html/ | sudo cp -r /var/www/html/ /tmp/backup/shipper-confbackup/
sudo chmod 755 -R /home/vunet/scripts/ | sudo cp -r /home/vunet/scripts/ /tmp/backup/shipper-confbackup/
sudo chmod 755 -R /etc/logstash/ | sudo cp -r /etc/logstash/ /tmp/backup/shipper1-backup/
echo “Taking a backup of index-patterns”
source $VUNET_VIRT_ENV/bin/activate; export PYTHONPATH=$VUNET_BASE_PATH/cairo/
python /home/vunet/workspace/cairo/tools/manage_vienna_data.py –server analyser –port 9200 get 1 1 /tmp/backup/shipper-confbackup index-pattern
python /home/vunet/workspace/cairo/tools/manage_vienna_data.py –server analyser –port 9200 get 1 1 /tmp/backup/shipper-confbackup dashboard
python /home/vunet/workspace/cairo/tools/manage_vienna_data.py –server analyser –port 9200 get 1 1 /tmp/backup/shipper-confbackup alert
python /home/vunet/workspace/cairo/tools/manage_vienna_data.py –server analyser –port 9200 get 1 1 /tmp/backup/shipper-confbackup report
sudo tar -czf /tmp/backup-“$(date +”%Y-%m-%d”)”.tar.gz /tmp/backup/
sudo chmod 755 -R /tmp/backup-“$(date +”%Y-%m-%d”)”.tar.gz
scp -r /tmp/backup-“$(date +”%Y-%m-%d”)”.tar.gz shipper2:/data/backup/
echo “Wait for 5 secs..”
sleep 5
sudo rm /tmp/backup-*