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.

DATE=$(date +'%d_%m_%Y')


# 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 \
--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 \

# Move it to the backup directory

mv AstroGR_$DATE.tar.gz $BKPDIR