WordPress WP Backup Sample Script

#!/bin/bash

# your backups will use these filenames.
db_backup_name=”tweenpath-db-backup-“`date “+%Y-%m-%d”`”.sql.gz”
wpfiles_backup_name=”tweenpath-files-backup-“`date “+%Y-%m-%d”`”.tar.gz”

## 1: database connection info. You can get these details from your wp-config file.
db_name="user_name"
db_username="database"
db_password="password"

## 2: Path to your WordPress Upload and Theme directories. Replace /home/username/ with path to your home directory.
wp_upload_folder="/home/tweenpath/public_html"

## 3: Path to your backup folder. Replace /home/username/ with path to your home directory.
backup_folder_path="/backup/tweenpath"

# backup MYSQL database, gzip it and send to backup folder.
mysqldump --opt -u$db_username -p$db_password $db_name | gzip > $backup_folder_path/$db_backup_name

# create a tarball of the wordpress files, gzip it and send to backup folder.
tar -czf $backup_folder_path/$wpfiles_backup_name $wp_upload_folder|

# delete all but 5 recent wordpress database back-ups (files having .sql.gz extension) in backup folder.
find $backup_folder_path -maxdepth 1 -name "*.sql.gz" -type f | xargs -x ls -t | awk 'NR>5' | xargs -L1 rm

# delete all but 5 recent wordpress files back-ups (files having .tar.gz extension) in backup folder.
find $backup_folder_path -maxdepth 1 -name "*.tar.gz" -type f | xargs -x ls -t | awk 'NR>5' | xargs -L1 rm

Src and Ref:

Auto BackUp WordPress Files Using a Simple Bash Script

Share

Upgrading WordPress Core Manually

  1. First create a full backup of your website. This is very important in case you make a mistake.
  2. Download the newest WordPress ZIP file from wordpress.org.
  3. Unzip the file into a directory on your local machine or in a separate directory on your website.
  4. Deactivate all of the plugins on your WordPress site.
  5. Go to your website root directory and delete your ‘wp-includes’ and ‘wp-admin’ directories. You can do this via sFTP or via SSH.
  6. Upload (or copy over) the new wp-includes and wp-admin directories from the new version of WordPress you unzipped to your website root directory to replace the directories you just deleted.
  7. Don’t delete your wp-content directory or any of the files in that directory. Copy over the files from the wp-content directory in the new version of WordPress to your existing wp-content directory. You will overwrite any existing files with the same name. All of your other files in wp-content will remain in place.
  8. Copy all files from the root (‘/’) directory of the new version of WordPress that you unzipped into your website root directory (or the root directory of your WordPress installation). You will overwrite any existing files and new files will also be copied across. Your wp-config.php file will not be affected because WordPress is never distributed with a wp-config.php file.
  9. Examine the wp-config-sample.php which is distributed with WordPress to see if any new settings have been added that you may want to use or modify.
  10. If you are upgrading manually after a failed auto-update, remove the .maintenance file from your WordPress root directory. This will remove the ‘failed update’ message from your site.
  11. Visit your main WordPress admin page at /wp-admin/ where you may be asked to sign-in again. You may also have to upgrade your database and will be prompted if this is needed. If you can’t sign-in, try clearing your cookies.
  12. Re-enable your plugins which you disabled earlier.
  13. Clear your browser cache to ensure you can see all changes. If you are using a front-end cache like ‘varnish’ you should also clear that to ensure that your customers can see the newest changes on your site.
    Your upgrade is now complete and you should be running the newest version of WordPress.

Ref: https://www.wordfence.com/learn/how-to-manually-upgrade-wordpress-themes-and-plugins/

Share

WordPress Backup Script

#!/bin/bash

# This script creates a compressed backup archive of the given directory and the given MySQL table. More details on implementation here: https://theme.fm
# Feel free to use this script wherever you want, however you want. We produce open source, GPLv2 licensed stuff.
# Author: Konstantin Kovshenin exclusively for Theme.fm in June, 2011
# Modification by Hasan T. Emdad tweenpath.net on August, 2020

# Set the date format, filename and the directories where your backup files will be placed and which directory will be archived.

NOW=$(date +"%Y-%m-%d-%H%M")
FILE="example.org.$NOW.tar"
BACKUP_DIR="/backups"
WWW_DIR="/var/www/example.org/"

# MySQL database credentials
DB_USER="mysqluser"
DB_PASS="mysqlpass"
DB_NAME="example_org"
DB_FILE="example.org.$NOW.sql"

# Tar transforms for better archive structure.
WWW_TRANSFORM='s,^var/www/example.org,www,'
DB_TRANSFORM='s,^var/www/example.org/backups,database,'

# Create the archive and the MySQL dump
tar -cvf $BACKUP_DIR/$FILE --transform $WWW_TRANSFORM $WWW_DIR
mysqldump --user=${DB_USER} --password=${DB_PASS} $DB_NAME > $BACKUP_DIR/$DB_FILE

# Append the dump to the archive, remove the dump and compress the whole archive.
tar --append --file=$BACKUP_DIR/$FILE --transform $DB_TRANSFORM $BACKUP_DIR/$DB_FILE
rm $BACKUP_DIR/$DB_FILE
gzip -9 $BACKUP_DIR/$FILE
Share

Easyengine installaiton on Debian 10

Install Easyengine WordPress on a Debian 10 VM (mine was a KVM).

The following procedure will install EE with following components;

  • Docker
  • WordPress Core
  • MariaDB
  • Nginx Server PHP-FPM
  • Redis Cache
  • Let’s encrypt SSL

Install EasyEngine on Linux

wget -qO ee rt.cx/ee4 && sudo bash ee
ee site create your_domain --type=wp --ssl=le --cache

For detailed installation or customizing your requirement, you may visit- https://easyengine.io/commands/site/create/

Read more

Share

Upgrade WordPress without FTP

Open /wp-config.php

Now the first thing you need to do is to open the wp-config.php file from your WordPress root folder (you may access this file from your WordPress installer folder). From the installation folder, the file is located at wordpress/wp-config.php

Insert FS_METHOD

Paste the following code to your wp-config.php file, preferably just below every other line of code.

define('FS_METHOD','direct');

Save and Try updating now. If you have inappropriate directory and file permission, might  encounter upgrade error. Try to do the following-

Web Server Ownership

The first level is actually to make sure that your web server has ownership over the directories:

chown -R www-data:www-data your-wordpress-directory

Directory Permissions

The second level is also required – you must make sure that the directory permissions are properly set:

sudo find /var/www/wordpress/ -type d -exec chmod 755 {} \; 
sudo find /var/www/wordpress/ -type f -exec chmod 644 {} \;
sudo chown -R www-data:www-data wp-content/plugins/
sudo chmod 775 wp-content
sudo chown -R www-data:www-data wp-content/
Share

Nginx wordpress fancy URL or permalink fixing

If your wordpress is installed in the root directory i.e. yourdomain.com, you can use the following directives-

location / {
try_files $uri $uri/ /index.php?$args;
}

# Add trailing slash to */wp-admin requests.
rewrite /wp-admin$ $scheme://$host$uri/ permanent;

location ~* \.(jpg|jpeg|png|gif|css|js|ico)$ {
expires max;
log_not_found off;
}

Or if your wordpress is installed inside a sub-directory the directive will be a bit different-

location /test/site1 {
try_files $uri $uri/ /test/site1/index.php?$args;
}

# Add trailing slash to */wp-admin requests.
rewrite /test/site1/wp-admin$ $scheme://$host$uri/ permanent;

Share