Created
August 10, 2023 08:18
-
-
Save fredbradley/d4a25e6c739874a2d39ec6ce5017b548 to your computer and use it in GitHub Desktop.
Old Backup Shell Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
########################################################################## | |
## IF YOU CHANGE THE PROCESS PLEASE WRITE ABOUT IT ## | |
## https://wiki.cranleigh.org/doku.php?id=website-2016-backup-process ## | |
########################################################################## | |
# 1. SET VARIABLES | |
BACKUPTIME="www.cranleigh.org-$(date +"%Y-%m-%d")" | |
BACKUP_DIRECTORY="/var/www/vhosts/www.cranleigh.org/auto_backups" | |
PATH_DIRECTORY="/var/www/vhosts/www.cranleigh.org" | |
SLACK_NAME="Senior School Network" | |
## the below line enables us to retrieve variables from a .config file (like $DBUSER, $DBPASS etc) | |
source $PATH_DIRECTORY/backup.config | |
echo -e "Starting MySQL Backups..." | |
# 2. DO LATEST MYSQL | |
mysqldump -u$DBUSER -p$DBPASS $DATABASE_NAME > $PATH_DIRECTORY/latest-dump_seniorschool.sql | |
echo -e "Placed the latest backup in the file system..." | |
# 3. DO MYSQLDUMP | |
echo -e "Now backing up to backups folder..." | |
mysqldump $DATABASE_NAME > $BACKUP_DIRECTORY/$BACKUPTIME.sql | |
echo -e "Starting GZIP" | |
gzip $BACKUP_DIRECTORY/$BACKUPTIME.sql | |
echo -e "Completed MySQL Backup" | |
# 4. DO FILE BACKUP | |
echo -e "${GREEN}Starting Filesystem Backup... this takes a while...${NC}" | |
tar -zcvf $BACKUP_DIRECTORY/$BACKUPTIME.tar -C $PATH_DIRECTORY doc_root/ repo/ wp-config.php latest-dump_seniorschool.sql | |
# tar --verbose --append --file=$BACKUP_DIRECTORY/$BACKUPTIME.tar repo/ | |
# tar --verbose --append --file=$BACKUP_DIRECTORY/$BACKUPTIME.tar wp-config.php | |
echo -e "Starting GZIP" | |
gzip $BACKUP_DIRECTORY/$BACKUPTIME.tar | |
echo -e "Completed Filesystem backup Backup" | |
# 5. FIND AND DELETE OLD FILES more than 7 days | |
echo -e "Checking if I need to delete any old backups..." | |
array=($(find $BACKUP_DIRECTORY -type f -mtime +6)) | |
for i in ${array[@]}; | |
do | |
name=$(basename "$i") | |
echo -e "Deleted $i backup" | |
rm $i | |
done; | |
echo -e "All 100% Done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment