Backup html folder, backup SQL Database and download locally

From rbachwiki
Revision as of 14:10, 15 June 2023 by Bacchas (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Master Script

echo "-----------------------------------"
echo "++++++++++ Running backup script, zipping dir and dump sql database ++++++++++"
echo ""
clientscripts/./client_run_backup_sql_zip.sh
sleep 5
echo "-----------------------------------"
echo "++++++++++ Download zip and sql files and copy to synology ++++++++++"
echo ""
clientscripts/./client_dlzipsql_cpto_synology.sh
sleep 5
echo "-----------------------------------"
echo "++++++++++ Delete zip and sql files on server ++++++++++"
clientscripts/./client_delete_zipsql.sh
echo "-----------------------------------"
echo "++++++++++ All scripts ran ++++++++++"

client_run_backup_sql_zip.sh

Running backup script, zipping dir and dump sql database

#!/bin/bash
ssh -i ~/.ssh/linode  root@10.1.1.1 /var/www/scripts/html_backup.sh
echo ""
echo "++++++++++++++++++ Finished running html backup script ++++++++++++++++"
echo ""
sleep 10
echo ""
echo "+++++++++++Running SQL Backup script ++++++"
ssh -i ~/.ssh/linode  root@10.1.1.1 /var/www/scripts/sql_backup.sh
echo ""
echo "+++++++++++++ Finish running SQL Backup script +++++++++++++++++"

html_backup.sh

#!/bin/bash
bkdate=`date +%F`
cd /var/www/html/
sleep 1
filename=vortex-$bkdate.zip
filenameadiva=adiva-$bkdate.zip
filenameyoko=yoko-$bkdate.zip
# zip htm folder
zip -r $filename /var/www/html/website0
sleep 5
zip -r $filenameadiva /var/www/html/website1
sleep 5
zip -r $filenameyoko /var/www/html/website2
sleep 5
count=`ls -l *.zip | wc -l 2> /dev/null`
if [ $count -ge 1 ]; then
mv *.zip /var/www/backups/html
fi

sql_backup.sh

#!/bin/bash
mdate=`date +%F`
cd /var/www/html/
mysqldump  dbname1> dbname1-$mdate.sql
sleep 5
mysqldump dbname> dbname-$mdate.sql
sleep 2
ls *.sql > /var/www/html/sqlfiles.txt
sleep 1
cd /var/www/html
count=`ls -l *.sql | wc -l 2> /var/www/errorsql.txt`
if [ $count -ge 1 ]; then
mv *.sql /var/www/backups/sql
fi

clientscripts/./client_dlzipsql_cpto_synology.sh

Download zip and sql files and copy to synology

#!/bin/bash
scp -i ~/.ssh/linode  10.1.1.1:/var/www/backups/html/*.zip .
sleep 10
scp -i ~/.ssh/linode  10.1.1.1:/var/www/backups/sql/*.sql .
echo "+++++++++ done copying form Remote ++++++++++++++++++"
sleep 10
echo "+++++++++++++++ Copying .zip and sql files to stan ++++++++++++++++++++++++++++++"
scp -i ~/.ssh/synology *.zip admin@192.168.2.120:/volume1/Linode/client
scp -i ~/.ssh/synology *.sql admin@192.168.2.120:/volume1/Linode/client
echo " +++++++++++++++++++++++++ Done copying to stan ++++++++++++++ "
sleep 5
echo "++++++++++++++++ deleting zip and sql files from local ++++++++++++++++++++++"
rm *.zip
rm *.sql

client_delete_zipsql.sh

Delete zip and sql files on server

ssh -i ~/.ssh/linode root@10.0.0.4 /var/www/scripts/delete_backups.sh


delete_backups.sh

#!/bin/bash
echo " ++++++++++ Deleting backup files ++++++++"
ls -la /var/www/backups/html
ls -la /var/www/backups/sql
sleep 5
rm /var/www/backups/html/*.zip
sleep 5
rm /var/www/backups/sql/*.sql
echo " +++++++++++++++++ done +++++++++++++++++"
ls -la /var/www/backups/html
ls -la /var/www/backups/sql

Home - Category