Backing up WordPress
February 06, 2021 —
Vinayak Gadkari
Backup has been on my mind, since I started blogging on WordPress. No blog owner wants to go through the pain of losing his ideas and re-creating his writings again.
After a night worth of efforts, here’s a simple script to backup a WordPress.com hosted blog in two ways.
Two Ways:
- Mirroring the entire blog site
- Using the “Export” feature of WordPress.com to export the blog site to a local xml file. This is a WordPress-only feature. The xml file can be imported in WordPress.com.
Steps:
- Use the Chrome extension Chrome cookie.txt export extension to download cookies to a file cookies.txt to be stored in the backup directory
- Use wget (command line downloader) to download the site. You can tweak the various wget options to download the site the way you want it.
Batch script to backup WordPress blog site
REM _mybackupblog.bat
@echo off
setlocal
set WP_SITE=<your site i.e. mysite.wordpress.com>
set WP_BKP_DIR=<your backup directory here>
set WGET_COMMON_OPTIONS=-nv --load-cookies %WP_BKP_DIR%\cookies.txt
REM Backup entire site
echo "Backing up WordPress blog site..."
wget %WGET_COMMON_OPTIONS% -m -p –E -k -D%WP_SITE% -P %WP_BKP_DIR%\site http://%WP_SITE%
REM Export entire site
echo "Exporting WordPress blog site..."
wget %WGET_COMMON_OPTIONS% -x http://%WP_SITE%/wp-admin/export.php?download=true -O %WP_BKP_DIR%\wordpress.xml
Batch script to schedule a daily (weekdays only) blog backup
REM _myschtasks.bat
@echo off
setlocal
schtasks /delete /F /TN "MyBlogBackup"
schtasks /create /RU %user% /RP %password% /SC WEEKLY /D MON,TUE,WED,THU,FRI /ST 13:40:00 /TN "MyBlogBackup" /tr "cmd.exe /c _mybackupblog.bat" /IT