CentOS 7

Simple Backup Script for Apache Web Server /w Mysql DB

Share on LinkedIn

This script may not be as clean as others but it gets the job done.

The purpose of this script is to backup both your entire web directory and database to a compressed file with date stamps. What you do with it from there is up to you.

Target: Web Directory and specific DB Instance – MUST know database name for this script

Environment Settings
Create /temp and /backups directories in /

mkdir temp
mkdir backups

See what’s in the directory by running the ls command


Output will be similar to this:

backups bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys temp tmp usr var

Create Script in / directory

vi My-Backup-Script.sh

The only items that need to be changed in this script are the items in ‘red‘.

#! /bin/bash
TIMESTAMP=$(date +"%F")

mkdir -p "$BACKUP_DIR/mysql"
$MYSQLDUMP --force --opt --user=$MYSQL_USER -p$MYSQL_PASSWORD $DATABASE | gzip > "$BACKUP_DIR/mysql/$DATABASE.gz"

mkdir -p "$BACKUP_DIR/web_dir"
tar --create --gzip --file=$DESTDIR$FILENAME $SRCDIR

tar --create --gzip --file=/backups/My-Backup-$TIMESTAMP.tgz $BACKUP_DIR

rm -rf /temp/*

echo "Backup of DB and Web Directory Complete!"

Make Script Executable

chmod +x My-Backup-Script.sh

Run cron job every day at 1130pm

sudo crontab -e

Add the following to your cronjob:

30 23 * * * /bin/bash /My-Backup-Script.sh

To Extract Backup files, you will need tar -zxvf for the main file and web directory file. You will need to use gzip -d for the database file.

How To Ensure WordPress Auto Updates Work on Self-Hosted Linux Machine

Share on LinkedIn

I’ve been meaning to get this posted for some time now. It could prove useful to someone hosting their own WordPress site on a self-hosted Linux machine.

When you are logged into the admin console of your WordPress site, you will get notifications of needed updates. You may also want to upload new themes from time-to-time.

When you go to perform the Automatic Update, it will work without issue so as long as your permissions are setup properly on your apache web server.

If you find yourself running into this issue, ssh into the backend of your apache web server and follow these simple steps:

1. Set ownership of /var/www/html and make changes recursive

chown -R apache:apache /var/www/html

2. Ensure the apache user/group can write to /var/www/html and make changes recursive

chmod -R 0775 /var/www/html

3. Restart apache

service httpd restart

Once you made those changes to the backend, try to run the update(s) again from the admin portal. You should be all good to go from there.