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

  • Apa itu Apple Creator Studio?
  • Inilah Alasan Kenapa Tidak Bisa Melihat Status WA Padahal Tidak Diprivasi dan Trik Mengatasinya!
  • Lupa Email Akun Higgs Domino? Ini Cara Mengatasinya
  • Apa itu WhatsApp Aero? Aman atau Tidak + Cara Downloadnya
  • Inilah Kenapa Paket JNE Muncul Status Nobody At Home dan Cara Mengatasinya Biar Nggak Panik!
  • Gagal Aktivasi BSI Mobile? Inilah Arti Pesan Error 53 Saving Account Not Registered dan Solusinya
  • Cara Cuan dari Hobi Baca Novel/Komik Online
  • Hp Vivo Kalian Muncul Notif Data Spasial Sistem Rusak? Begini Trik Mengatasinya Sampai Tuntas!
  • Cara Buat Link Ujian Mencintai Diam-Diam Google Form, Tes Seberapa Besar Perasaan Kalian ke Crush!
  • Ini Penjelasan Mengenai Cara Mengubah Dosa Menjadi Diamond Game FF ML dan Saldo Shopeepay yang Sedang Viral
  • Trik Supaya Bisa Dapat Potongan Harga Rp100 di TikTok Tanpa Harus Reset HP!
  • Cara Input Bantuan IFP dan Laptop di Dapodik 2026.B, Aset Sekolah Aman
  • Cara Cairkan Rp170.000 dari Clear Blast, Terbukti Membayar ke DANA Tanpa Ribet!
  • Inilah Fakta Video Viral Arohi Mim 3 Menit 24 Detik yang Bikin Geger Netizen!
  • Inilah Sebenarnya Video Botol Aqua Viral yang Bikin Netizen TikTok Heboh dan Penasaran!
  • Takut Chat Hilang? Ini Cara Mudah Backup WA GB ke Google Drive yang Wajib Kalian Tahu!
  • Tutorial Ambil Barang Gratis di Akulaku, Modal Undang Teman Doang!
  • Ini Arti Kode Error FP26EV dan FP27EV di Aplikasi BriMO Serta Cara Mengatasinya!
  • Cara Jadi Clipper Modal Ngedit Video di TryBuzzer, Cocok Banget Buat Pemula!
  • Cara Pakai Beb6 Wifi Password Untuk Cek Jaringan di Sekitar Kalian
  • Inilah Review Lengkap Apakah Turbo VPN Extension Aman
  • Apa itu Toko Biru? Ini Istilah Olshop yang Perlu Kamu Tahu
  • Adswerve Inc Penipu? Ini Fakta di Balik Konsultan Digital Terkemuka Dunia!
  • Sering Ditelepon 08111? Simak Apakah Ini Penipuan atau Marketing Resmi Telkomsel
  • Inilah Cara Daftar dan Login Subsidi Tepat LPG 3 kg di Merchant Apps MyPertamina!
  • Akademi Crypto Penipu?
  • Belum Tahu Arti Paket Sedang Transit di TikTok Shop? Ternyata Ini Maksudnya Biar Kalian Nggak Panik!
  • Akun Paylater Tiba-tiba Diblokir? Jangan Panik, Gini Cara Mengatasinya Biar Lancar Jaya!
  • HP Vivo Sering Mati Sendiri Padahal Baterai Masih Banyak? Ini Penyebab dan Solusinya!
  • Inilah Cara Mengatasi BNI Mobile Banking Transaksi Tidak Dapat Dilanjutkan dan Penjelasan Kode Errornya!
  • Apa itu Zoom Stealer? Ini Definisi dan Bahaya Tersembunyi di Balik Ekstensi Browser Kalian
  • Apa itu Skandal BlackCat Ransomware?
  • Grain DataLoader Python Library Explained for Beginners
  • Controlling Ansible with AI: The New MCP Server Explained for Beginners
  • Is Your Headset Safe? The Scary Truth Bluetooth Vulnerability WhisperPair
  • Perbedaan GPU vs TPU, Mana yang Terbaik
  • Tutorial Langfuse: Pantau & Optimasi Aplikasi LLM
  • Begini Teknik KV Caching dan Hemat Memori GPU saat Menjalankan LLM
  • Apa itu State Space Models (SSM) dalam AI?
  • Begini Cara Mencegah Output Agen AI Melenceng Menggunakan Task Guardrails di CrewAI
  • Apa itu Zoom Stealer? Ini Definisi dan Bahaya Tersembunyi di Balik Ekstensi Browser Kalian
  • Apa itu Skandal BlackCat Ransomware?
  • Apa itu ToneShell? Backdoor atau Malware Biasa?
  • Apa itu Parrot OS 7? Ini Review dan Update Terbesarnya
  • Clipper Malware? Ini Pengertian dan Bahaya yang Mengintai Kalian
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

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