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 and store them on my laptop.

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 \

# Remove the database file
rm DB_$DATE.sql

# Move it to the backup directory
mv AstroGR_$DATE.tar.gz $BKPDIR

# Instructions to scp

echo ""
echo "Now from your laptop go into ~/andromina/AstroGR_Backup/ and run"

And this is how the script looks like

scp\*gz .