This bash script will backup your WordPress website files and database

Replace the [brackets and text] with your information!
#!/bin/bash
####################################
#
# Backup WordPress Website
#
####################################

# What to backup. Use trailing slash.
backup_files="[/home/www/public/]"    

# Where to backup to. Use trailing slash.
dest="[/mnt/backups/]"

# Create archive filename.
NOW=$(date +"%Y%m%d%H%M%S")
#day=$(date +%A)
hostname=$(hostname -s)
archive_file="$hostname-$NOW.tgz"
archive_file_sql="$hostname-$NOW.sql"

# Print start status message for database.
echo "Backing up $backup_files to $dest$archive_file_sql"
date
echo

# Backup database
# Best practice is to use -p without the Password. You will be prompted to enter the password.
mysqldump --no-tablespaces -u [mysql-username] -p[Password] [MySQL-database-name] > $dest$archive_file_sql

# Print start status message for website files.
echo "Backing up $backup_files to $dest$archive_file"
date
echo

# Backup the files using tar.
tar czpf $dest$archive_file $backup_files

# Print end status message.
echo
echo "Backup finished"
date

# Long listing of files in $dest to check file sizes.
ls -lh $dest
Leave A Comment

Total Views: 338Daily Views: 6

This bash script will backup your WordPress website files and database

Replace the [brackets and text] with your information!
#!/bin/bash
####################################
#
# Backup WordPress Website
#
####################################

# What to backup. Use trailing slash.
backup_files="[/home/www/public/]"    

# Where to backup to. Use trailing slash.
dest="[/mnt/backups/]"

# Create archive filename.
NOW=$(date +"%Y%m%d%H%M%S")
#day=$(date +%A)
hostname=$(hostname -s)
archive_file="$hostname-$NOW.tgz"
archive_file_sql="$hostname-$NOW.sql"

# Print start status message for database.
echo "Backing up $backup_files to $dest$archive_file_sql"
date
echo

# Backup database
# Best practice is to use -p without the Password. You will be prompted to enter the password.
mysqldump --no-tablespaces -u [mysql-username] -p[Password] [MySQL-database-name] > $dest$archive_file_sql

# Print start status message for website files.
echo "Backing up $backup_files to $dest$archive_file"
date
echo

# Backup the files using tar.
tar czpf $dest$archive_file $backup_files

# Print end status message.
echo
echo "Backup finished"
date

# Long listing of files in $dest to check file sizes.
ls -lh $dest
Leave A Comment