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

  • ZenBook S16, Vivobook Pro 15 OLED, ProArt PX13, dan ROG Zephyrus G14, Laptop Bagus dengan Layar OLED!
  • Caranya Ngebangun Website Directory dengan Traffic Tinggi dalam Seminggu!
  • Cara Mengembangkan Channel YouTube Shorts Tanpa Wajah
  • Inilah Cara Menghitung Diskon Baju Lebaran Biar Nggak Bingung Saat Belanja di Mall!
  • Cara Jitu Ngebangun Bisnis SaaS di Era AI Pakai Strategi Agentic Workflow
  • Inilah Rincian Gaji Polri Lulusan Baru 2026, Cek Perbedaan Jalur Akpol, Bintara, dan Tamtama Sebelum Daftar!
  • Inilah 5 Channel YouTube Membosankan yang Diam-diam Menghasilkan Banyak Uang
  • Inilah Cara Pakai Google Maps Offline Biar Mudik Lebaran 2026 Nggak Nyasar Meski Tanpa Sinyal!
  • Inilah Alasan Mahkamah Agung Tolak Kasasi Google, Denda Rp202,5 Miliar Resmi Menanti Akibat Praktik Monopoli
  • Inilah Cara Daftar dan Syarat SPMB SMK Boarding Jawa Tengah 2026, Sekolah Gratis Sampai Lulus!
  • Inilah Daftar Sekolah Kedinasan 2026 untuk Lulusan SMK, Bisa Kuliah Gratis dan Berpeluang Besar Langsung Jadi CPNS!
  • Inilah Pajak TER: Skema Baru PPh 21 yang Nggak Bikin Pusing, Begini Cara Hitungnya!
  • Inilah Jadwal Resmi Jam Buka Tol Jogja-Solo Segmen Prambanan-Purwomartani Saat Mudik Lebaran 2026
  • Inilah Cara Mendapatkan Witherbloom di Fisch Roblox, Rahasia Menangkap Ikan Paling Sulit di Toxic Grove!
  • Kenapa Indomart Point Bisa Kalahkan Bisnis Kafe?
  • Inilah Cara Mendapatkan Rotten Seed di Fisch Roblox, Lokasi Rahasia di Toxic Grove Buat Unlock Toxic Lotus!
  • Inilah Cara Zakat Crypto Kalian Bisa Jadi Pengurang Pajak Berdasarkan Aturan Resmi Pemerintah!
  • Inilah Perbandingan Airwallex vs Payoneer 2026: Jangan Sampai Profit Kalian Ludes Gara-Gara Biaya Admin!
  • Inilah Roadmap 7 Tahap Bangun Bisnis Digital dari Nol Biar Nggak Cuma Putar-Putar di Tempat!
  • Inilah Cara Tetap Gajian dari YouTube Meski View Masih Ratusan, Penasaran?
  • Inilah Alasan Akun TikTok Affiliate GMV 270 Juta Kena Banned Permanen!
  • Inilah Bahaya Astute Beta Server APK, Jangan Sembarang Klik Link Download FF Kipas 2026!
  • Inilah Bahaya Nonton Film di LK21 dan IndoXXI, Awas Data Pribadi dan Saldo Rekening Kalian Bisa Ludes!
  • Inilah Kronologi & Video Lengkap Kasus Sejoli Tambelangan Sampang Viral, Ternyata Gini Awal Mulanya!
  • Inilah Alasan Kenapa Koin Nego Neko Shopee Nggak Bisa Dipakai Bayar Full dan Cara Rahasia Dapetinnya!
  • Inilah Cara Menjawab Pertanyaan Apakah di Sekolahmu Sudah Ada IFP/PID dengan Benar dan Profesional
  • Inilah Fakta Isu Roblox Diblokir di Indonesia 2026, Benarkah Akan Ditutup Total?
  • Inilah Penyebab dan Cara Mengatasi FF Kipas My ID Verify UID Biar Akun Tetap Aman
  • Inilah Deretan HP RAM 8GB Harga di Bawah 2 Juta Terbaik 2026, Spek Dewa Tapi Nggak Bikin Kantong Jebol!
  • Contoh Cara Buat SK Panitia TKA 2026
  • How to Fix Python Not Working in VS Code Terminal: A Troubleshooting Guide
  • Game File Verification Stuck at 0% or 99%: What is it and How to Fix the Progress Bar?
  • Why Does PowerPoint Underline Hyperlinks? Here is How to Remove Them
  • AI Bug Hunting with Semgrep
  • What is the Excel Power Query 0xc000026f Error?
  • Claude Code Tips: Don’t Overuse SKILL.md!
  • How to Planning Cinematic AI Film Production: A Step-by-Step Tutorial Using LitMedia Tools
  • 6 Innovative AI Tools for 2026: From Voice Cloning to Advanced Automation Systems
  • How to Run Hunter Alpha: The Free 1 Trillion Parameter AI Agent on OpenClaw
  • Build Your Own Self-Improving AI: A Guide to Andrej Karpathy’s Autoresearch and Claude Code
  • 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