August 1, 2020

WordPress: Backup script

I do not like plugins. I prefer the command line and a bit of common sense. This is the way I make backups of my whole web page.

#!/bin/sh
DATE=$(date +'%d_%m_%Y')

BKPDIR=/path/to/my/backups

# Remove the last file.tar.gz in the backup directory

ls -1t $BKPDIR/*tar.gz | tail -n +1 | xargs rm -f

# Dump the database

mysqldump --no-tablespaces --add-drop-table --host=blabla-bloblo.data.ie \
--user=dbo34568762 --password=MyAweSomePassWord db_name \
> DB_$DATE.sql

# Create a tar.gz of the whole directory where wp is

tar cvfz AstroGR_$DATE.tar.gz \
/path/to/my/wp/installation/AstroGR \
DB_$DATE.sql

# Move it to the backup directory

mv AstroGR_$DATE.tar.gz $BKPDIR