User Tools

Site Tools


my_backup_pi_scripts

My Backup Pi Scripts



These are the scripts the backup pi is using to pull all the files from the webserver and wiki pi's. There are two scripts:

1. The backup script for webserver1 (cameraangle and shotlive) 2. The backup script for the wiki server

These are both run once a week by a cron job (sudo crontab -e)

Webserver1 Script (wikibackup) Latest

#!/bin/bash
#
# Script to backup webserver pi
#
#
# Alan Walker - Nov 2016
#
#
# stuff this script does
# backup (rsync) cpg15x on webserver1
# backup ShotLive on webserver1
# backup (mysqldump) database on webserver1
#
#
# backup (rsync) cpg15x on webserver1
# create new backup folder
echo "Creating folder /mnt/usbstorage/backups/webserver1/"$(date '+%Y-%m-%d')
# make a folder with the current date
mkdir /home/pi/Backups/webserver1/$(date '+%Y-%m-%d')
#
# copy files from cpg15x on webserver to this server
echo "Copying cpg15x files to /mnt/usbstorage/backups/webserver1/"$(date '+%Y-%m-%d')
sudo sshpass -p "Password" rsync --verbose --recursive --perms --executability --acls --xattrs --owner --group  pi@192.168.1.9:/mnt/usbhdd/cpg15x /home/pi/Backups/webserver1/$(date '+%Y-%m-%d')
#
# copy files from ShotLive on webserver to this server
echo "Copying ShotLive files to /mnt/usbstorage/backups/webserver1/"$(date '+%Y-%m-%d')
#sudo rsync --verbose --recursive --perms --executability --acls --xattrs --owner --group  pi@192.168.1.10:/home/pi/ShotLive /mnt/usbstorage/backups/webserver1/$(date '+%Y-%m-%d')
sudo sshpass -p "Password" rsync --verbose --recursive --perms --executability --acls --xattrs --owner --group  pi@192.168.1.9:/mnt/usbhdd/ShotLive /home/pi/Backups/webserver1/$(date '+%Y-%m-%d')
#
# Backup MySQL Database (the one database is used for both ShotLive and Cameraangle)
echo "Backup database to /mnt/usbstorage/backups/webserver1/"$(date '+%Y-%m-%d')
sudo mysqldump --host 192.168.1.9 -P 3306 -u username -pPassword alan_gallery > /home/pi/Backups/webserver1/$(date '+%Y-%m-%d')/alan_gallery.sql
#
#
echo ""
echo "Finished"



Wiki Server Backup Script (wikibackup)

#!/bin/bash
#
# Script to backup wiki pi
#
#
# Alan Walker - Nov 2016
#
#
# stuff this script does
#
# backup wiki (rsync) on wiki pi
#
#
# backup (rsync) wiki server
# create new backup folder
echo "Creating folder /mnt/usbstorage/backups/wiki/"$(date '+%Y-%m-%d')
# make a folder with the current date
mkdir /home/pi/Backups/wiki/$(date '+%Y-%m-%d')
#
# copy files from /home/pi/dokuwiki on wiki server to this server
echo "Copying dokuwiki files to /home/pi/Backups/wiki/"$(date '+%Y-%m-%d')
#
#
sudo sshpass -p "Password" rsync --super --verbose --recursive --perms --executability --acls --xattrs --owner --group  pi@192.168.1.9:/mnt/usbhdd/dokuwiki /home/pi/Backups/wiki/$(date '+%Y-%m-%d')
#
#
echo ""
echo "Finished"


Cron Automation

To automate this process, I am using the following Cron job (use crontab -e)

# This job is to backup the webserver files and database at 3am every sunday
0 3 * * 0 /mnt/usbstorage/backups/scripts/websvr1backup
#
#
# This job is to backup the wiki server every sunday at 2am
0 2 * * 0 /mnt/usbstorage/backups/scripts/wikibackup



my_backup_pi_scripts.txt · Last modified: 2017/02/28 18:00 (external edit)