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

  • Inilah Syarat dan Prosedur Ikut Seleksi Siswa Unggul ITB Jalur Tes Tulis 2026/2027
  • Inilah Kronologi & Latar Belakang Kasus Erin Taulany vs ART Hera: Masalah Facebook Pro?
  • Inilah Alasan Kenapa Ending Film Children of Heaven diubah di Indonesia
  • Ini Alasan Hanny Kristianto Cabut Sertifikat Mualaf Richard Lee
  • Inilah Syarat Dokumen SSU ITB 2024-2026 yang Wajib Kalian Siapkan Supaya Nggak Gagal Seleksi Administrasi
  • Inilah Episyrphus Balteatus, Lalat Unik Penyamar yang Sangat Bermanfaat bagi Taman Kalian
  • Inilah Cara Lolos Seleksi Siswa Unggul ITB Lewat Jalur Tes Tulis Biar Jadi Mahasiswa Ganesha
  • Inilah Penemuan Fosil Hadrosaurus yang Ungkap Bahwa Penyakit Langka Manusia Sudah Ada Sejak Zaman Prasejarah
  • Inilah Penemuan Terbaru yang Mengungkap Bahwa Sunburn Ternyata Disebabkan Oleh Kerusakan RNA
  • Inilah Alasan Kenapa Manusia Lebih Sering Hamil Satu Bayi daripada Kembar Menurut Penelitian Terbaru
  • Inilah Syarat dan Cara Pendaftaran IMEI Internasional Mulai Mei 2026
  • Bocoran Spek Samsung Galaxy S27 Ultra Nih, Kamera 3X Hilang + Teknologi AI
  • Inilah Perbedaan Motorola G47 dan Motorola G45, Cuma Kamera 108 Megapiksel Doang?
  • Update Baru Google Gemini: Bisa Bikin File Word, PDF, Excel secara Otomatis
  • Rekomendasi Motor Listrik 2026 Anti Mogok!
  • Ini Loh Honda Vision 110, Motor Baru Seharga Beat & Rangka eSAF Khusus Pasar Eropa
  • Inilah Mobil-Mobil Paling Cocok Transisi ke Bioetanol E20 dan Biodiesel B50!
  • Inilah Ternyata Batas Minimal Daya Cas Mobil Listrik di Rumah
  • DJP Geser Batas Akhir Lapor Pajak Sampai 31 Mei 2026
  • PKB Tanggapi Dingin Usul Yusril Ihza Mahendra Soal Parliamentary Treshold 13 Kursi
  • LPTNU Kritik Keras Rencana Penutupan Prodi: Kenapa Tidak Komprehensi & Berbasis Problematika Nyata?
  • Gus Rozin PWNU Jawa Tengah Setuju Cak Imin, Konflik PBNU bikin Warga Kesal dan Tidak Produktif
  • Pengamat: Prabowo Harus Benahi KAI, Aktifkan juga Jalur Kereta Lama & Baru
  • Sekjend PBNU: Jadwal Muktamar Usulan PWNU Sejalan Hasil Rapat Pleno & Rais Aam
  • PKB Desak Hukuman Maksimal Kasus Little Aresha & Evaluasi Total Sistem Penitipan Anak secara Nasional
  • PKB Usul Modernisasi Sistem Kereta dan CCTV di Kabin Masinis, Setuju?
  • Menteri PPA Arifah Fauzi Minta Maaf Soal Polemik Pindah Gerbong Wanita di KRL
  • Cara Kirim Robux Mudah di Roblox Beli Skin Shirt Preview
  • Kronologi kasus dugaan penyebaran konten asusila oleh anak anggota DPRD Kutai Barat?
  • Inilah Alasan Kenapa Gelembung Air di Luar Angkasa Bisa Jadi Eksperimen Fisika yang Keren Banget
  • How to build a high-performance private photo cloud with Immich and TrueNAS SCALE
  • How to Build an Endgame Local AI Agent Setup Using an 8-Node NVIDIA Cluster with 1TB Memory
  • How to Master Windows Event Logs to Level Up Your Cybersecurity Investigations and SOC Career
  • How to Build Ultra-Resilient Databases with Amazon Aurora Global Database and RDS Proxy for Maximum Uptime and Performance
  • How to Build Real-Time Personalization Systems Using AWS Agentic AI to Make Every User Feel Special
  • How to Master Mistral Medium 3.5: A Comprehensive Guide to the 128B Dense Open-Source Giant
  • How to Create Professional YouTube Content Using HeyGen AI Without Showing Your Face
  • How to Boost Your Local AI Speed with Gemma 4 Multi-Token Prediction
  • How to 3x your AI speed with Google’s Gemma 4 MTP Drafters: A step-by-step guide to lightning-fast inference
  • How to Master Google Pomelli: The Ultimate AI Tool for Creating Professional Marketing Content in Minutes
  • Apa itu Spear-Phishing via npm? Ini Pengertian dan Cara Kerjanya yang Makin Licin
  • Apa Itu Predator Spyware? Ini Pengertian dan Kontroversi Penghapusan Sanksinya
  • Mengenal Apa itu TONESHELL: Backdoor Berbahaya dari Kelompok Mustang Panda
  • Siapa itu Kelompok Hacker Silver Fox?
  • Apa itu CVE-2025-52691 SmarterMail? Celah Keamanan Paling Berbahaya Tahun 2025

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