Skip to content

emka.web.id

menulis pengetahuan – merekam peradaban

Menu
  • Home
  • Tutorial
  • Search
Menu

Automatically replace files when updating WordPress with Shell Script

Posted on June 10, 2012

WordPress is quick and easy to install and update, but the quicker you can make these operations the better, right? If you have shell access to the server where your WordPress copy is installed, it is possible to perform all the operations in Step 1 of the Manual WordPress Update Procedure with the shell script below. It will save you a few minutes, which may seem too little, but is great if you maintain more than one copy of WordPress. That, however, is not the main reason to use a script like this. Its bigger advantage is reducing the possibility of human error by doing things by hand, at the prompt or with the mouse is the same.

The scripts takes two parameters: the first is the complete URL of the zipped WordPress files that you need in order to upgrade. The second is the directory, called WP_ROOT, where the WordPress installation you need to upgrade lives. You will note that in my script $WP_ROOT is only the name of that directory, not the complete path to it, which in the script is $HTML_ROOT/$WP_ROOT. I have do this because I have several, independent copies of WordPress running on the same server, all living in different subdirectories of my $HTML_ROOT, named with the name of each blog. Therefore, this choice of variables sounds more natural to me. When I want to update http://stop.zona-m.net, I will type `upgrade_wordpress.sh http://wordpress.org/wordpress-3.1.1.zip stop`. When I want to update http://strider.zona-m.net, instead, I will type “strider” instead of “stop”, and so on. Here is the script. Enjoy it, but remember to read the warnings at the end of this page first!

[sourcecode language=”bash”]
#! /bin/bash
# upgrade_wordpress.sh
# This script performs automatically the operations described in the section
# "Manual Update – Step 1" of http://codex.wordpress.org/Updating_WordPress
# Copyright 2011 M. Fioretti http://stop.zona-m.net
# Released under GPL V2 license
#
# $1 URL of latest WordPress version, zipped
# $2 Root directory of the WordPress installation that must be upgraded

WP_ROOT=$2
HTML_ROOT=/var/www/html/wp
TEMP_DIR=/tmp/temp_wp_update

# Step 1.1 and 1.2: get latest WordPress, unpack it in temporary directory
mkdir $TEMP_DIR
cd $TEMP_DIR
wget $1
unzip -q wordpress*.zip

# Step 1.3: Delete the old wp-includes and wp-admin directories
rm -rf $HTML_ROOT/$WP_ROOT/wp-includes $HTML_ROOT/$WP_ROOT/wp-admin

# Step 1.4: "upload" the new wp-includes and wp-admin directories
cp -r -p $TEMP_DIR/wordpress/wp-includes $TEMP_DIR/wordpress/wp-admin $HTML_ROOT/$WP_ROOT

# Step 1.5: "Upload" the individual files from the new wp-content folder
# to your existing wp-content folder, overwriting existing files.

cd $TEMP_DIR/wordpress/wp-content/
find . -type f | sort > $TEMP_DIR/new_wp_content_files_list
tar cf $TEMP_DIR/wp-content-files-to-replace.tar -T $TEMP_DIR/new_wp_content_files_list
cd $HTML_ROOT/$WP_ROOT/wp-content
tar xf $TEMP_DIR/wp-content-files-to-replace.tar

# Step 6: "Upload" all new loose files from the root directory of the new
# version to your existing wordpress root directory

cd $TEMP_DIR/wordpress
tar cf $TEMP_DIR/loose_files_in_wp_rootdir.tar license.txt readme.html *php
cd $HTML_ROOT/$WP_ROOT
tar xf $TEMP_DIR/loose_files_in_wp_rootdir.tar

# Final step: remove temporary files, remember to check the configuration

rm -rf $TEMP_DIR
echo "you should take a look at the wp-config-sample.php file, to see if any new settings have been introduced that you might want to add to your own wp-config.php"
[/sourcecode]

Note:

If you reload the WordPress admin page just after running the script you’ll get the “let’s upgrade the database” button, and everything should be OK after that. I have tested this script myself to update both http://tips.zona-m.net/ and this website from WordPress 2.8.1 on a Centos VPS and as far as I can see it worked just fine.

As everything done with shell scripts, howeverm this thing is powerful enough to both save you time and to hurt your blog if there is some bug or if something changes in the official WordPress instructions before I notice it and update this page. Of course, the script is provided as is, without warranties, and you should (because you should do it anyway!!!) back everything up right before running it.

The script could have been even shorter. I deliberately wrote it in that way to have the same steps as the procedure described at WordPress.org, and make it easier to update if/when something changes in WordPress. If you find errors or ways to improve it, please write them as a comment and I will update the page as soon as possible. Thanks.

via Zona-m

Terbaru

  • Masih Pusing Hitung Gaji Manual? Waktunya Pakai Aplikasi HR
  • Apa Itu Dustruco? Ini Pengertian dan Cara Pasangnya di HP Kalian
  • Apa Itu Aplikasi Dooie Live? Ini Pengertian dan Cara Pakai Aplikasinya untuk Cari Jodoh
  • Apa Itu Battle Emote Jefri Nichol dan Om Telolet Om di MLBB? Ini Penjelasannya
  • Apa itu Game Luna Mobile dan Bagaimana Cara Menangnya?
  • Apa Itu Kompensasi Sistem Trail Mobile Legends? Ini Penjelasan dan Cara Klaim Hadiahnya
  • Apa Itu Update Google Pixel 2 Desember 2025? Ini Penjelasannya!
  • Ini Cara Reset Desil di Aplikasi Cek Bansos Biar Valid (Update Januari 2026)
  • Apa Itu EZNET Wireless dan Fiber Optic? Ini Perbedaan dan Pengertian Lengkapnya
  • Pengertian Rework Magic Wheel dan Rank Mythic Eternal: Apa itu Perubahan Sistem Baru Mobile Legends?
  • Apa Itu Diamond Combo? Pengertian Game Puzzle Viral yang Katanya Bisa Hasilkan Cuan
  • Apa Itu Showbox? Pengertian, Fungsi, dan Cara Menggunakannya di Android
  • Cara Mengatasi Fitur Monet Facebook Pro Tiba-tiba Hilang
  • Google Bikin Kejutan! Pixel 10 Diskon Gila-gilaan di YouTube Premium
  • Apa Itu Google CC? Ini Pengertian Agen Produktivitas AI Eksperimental Terbaru
  • Apa Itu Ultras Seblak di eSport? Pengertian dan Fenomena Baru Suporter eSport
  • Android 16: Animasi Folder Baru yang Mengubah Cara Kita Berinteraksi!
  • Android 16: Notifikasi Lokasi ‘Blue Dot’ – Fitur Baru yang Perlu Kalian Ketahui!
  • Apa Itu Risiko Auto Click di Event Spongebob Mobile Legends? Ini Penjelasannya
  • Apa Itu Fitur Eksperimental Windows? Ini Pengertian dan Cara Menonaktifkannya
  • Apa Itu Android 16 Beta 1? Ini Pengertian dan Fitur Terbarunya
  • Belum Tahu? Ini Trik Supaya Bisa Dapat Skin Patrick Mobile Legends dengan Harga Murah
  • Pixel Desember 2025: Update Besar Siap Meluncur, Apa yang Baru?
  • Apa Itu HYFE XL Prioritas? Ini Pengertian, FUP, dan Realita Kecepatannya
  • Pengertian Render dan Convert: Apa Bedanya dalam Video Editing?
  • Cara Mengatasi Aplikasi Office yang Terus Muncul dan Menerapkan Perubahan Pengaturan Privasi
  • Pixel Launcher Mendapatkan Sentuhan Google Search Baru!
  • Penyebab Aplikasi Wondr BNI Tidak Bisa Dibuka
  • Kode 0425 Daerah Mana? Ini Pengertian dan Fakta Sebenarnya
  • Apa Itu SSS CapCut? Pengertian Downloader Video Tanpa Watermark yang Wajib Kalian Tahu
  • Apa Itu AI Kill Switch di Firefox? Ini Pengertian dan Detail Fitur Terbarunya
  • Apa Itu Platform Modular Intel Alder Lake N (N100)? Ini Pengertian dan Spesifikasinya
  • Apa Itu Armbian Imager? Pengertian Utilitas Flashing Resmi untuk Perangkat ARM Kalian
  • Apa Itu OpenShot 3.4? Pengertian dan Fitur LUT Terbaru untuk Grading Warna
  • Flatpak 1.16.2: Sandbox Baru untuk GPU Intel Xe dan VA-API
  • Apa Itu Elestio Get A Team? Ini Pengertian Karyawan AI Digital
  • Apa itu RunPod? Ini Pengertian dan Tutorial Cara Deploy Pod Pertamamu
  • Apa Itu Migrasi Pod di RunPod? Ini Pengertian dan Cara Kerjanya
  • Loading Model AI Lama? Coba Fitur Cached Models RunPod Ini, Hemat Waktu & Biaya!
  • Replicate Diakuisisi Cloudflare? Tenang, Ini Justru Kabar Baik Buat Developer AI
  • Apa Itu Kerentanan UEFI? Pengertian Celah Keamanan DMA pada Booting Awal
  • Apa Itu Serangan Siber Infrastruktur Kritikal? Belajar dari Kasus Peretasan Air Bersih Denmark
  • Apa Itu Error Update MSMQ di Windows 10? Ini Penjelasan Lengkap dan Solusinya
  • Apa Itu “I Am Not a Robot – reCAPTCHA Verification ID: 2165”? Ini Pengertian dan Bahayanya
  • Apa Itu Serangan Clop Ransomware pada CentreStack? Ini Pengertian dan Dampaknya
Beli Morning Star Kursi Gaming/Kantor disini: https://s.shopee.co.id/805iTUOPRV
Beli Pemotong Rumput dengan Baterai IRONHOOF 588V Mesin Potong Rumput 88V disini https://s.shopee.co.id/70DBGTHtuJ

©2025 emka.web.id | Design: Newspaperly WordPress Theme