How to Download and Extract Tarball Contents into an Existing Directory

mediawikitar

I have a MediaWiki 1.32.0 website which I want to upgrade, hosted on a CentOS "Shared Server" environment.
It is an all-core website with no added extensions, skins and images (besides logo)

To upgrade I need to change generally all files in the website's directory to those inside a directory of a newer version's MediaWiki installment (available inside a tartball) by a general overriding operation.

To download a latest MediaWiki tarball containing such directory (as of 13/08/19) one could execute:

wget https://releases.wikimedia.org/mediawiki/1.33/mediawiki-1.33.0.tar.gz

In my existing website directory, there are these files I already edited and shouldn't override:

  1. LocalSettings.php
  2. robots.txt
  3. .htaccess
  4. example.com.png (logo image)
  5. googlec69e044fede13fdc.html (Google search console verification file)

How could I download, and extract all files from directory in tarball to override a my current MediaWiki directory to override all files besides listed exceptions (such as the files listed above)?
I do plan to backup the old directory before changes manually as priming part of the script; adding a condition to continue only of the backup was done might be a nice idea; all of this, aside from having automatic daily backups).

Best Answer

Extracting the tarball you have in your question will create the directory mediawiki-1.33.0 which contains the following sub-directories:

$ tree -dL 1 mediawiki-1.33.0
mediawiki-1.33.0
├── cache
├── docs
├── extensions
├── images
├── includes
├── languages
├── maintenance
├── mw-config
├── resources
├── skins
├── tests
└── vendor

12 directories

Assuming these are also the directories you need in a proper mediawiki installation, all you need to do is:

  1. Backup the files you want to keep, using -p to keep the permissions, ownership and timestamps unchanged.

    cp -p LocalSettings.php robots.txt .htaccess example.com.png googlec69e044fede13fdc.html /some/other/path
    
  2. Extract the tarball

    tar xvzf mediawiki-1.33.0.tar.gz
    
  3. Copy the files to wherever they should be

    cp -a mediawiki-1.33.0/* /path/to/mediawiki/instrallation
    

    This will overwrite any existing files.

  4. Copy the backups back to their original locations

    cp -p /some/other/path/LocalSettings.php /original/path