Script Webseite Duplizieren / Testseite: Unterschied zwischen den Versionen

Aus revampedia
 
(14 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 1: Zeile 1:
Es soll ein Script erstellt werden um Webseiten inkl. Datenbank von produktiv- zu testserver zu kopieren, also eine testseite zu erstellen.
 
  
Geplantes Set-up:
+
Modulares Script zum kopieren von Webseiten inkl. Datenbank. Nützlich um eine Test-Entwicklungsseite zu erstellen.
<pre>
 
Produktivserver
 
- webserver
 
- db-server
 
  
Testserver
+
Automatische Anpassung von Joomla Config.
- web- und db-server
+
 
</pre>
+
=== Script ===
 +
 
 +
Code on github: https://github.com/rebootl/website-copy/
 +
 
 +
Siehe auch Readme dort.
 +
 
 +
=== Anwendung revamp-it ===
 +
 
 +
Anwendung zum erstellen von Testseite auf flunder-web siehe: [[Intern:Revamp-it.ch_auf_flunder-web#Testseite]]
 +
 
 +
Anwendung auf Test-/Entwicklunsserver delfin-web. Anleitung, Beispiel: [[Intern:Anleitungen/Webentwicklung_auf_delfin-web#Anwendung_Script_zum_kopieren_von_Webseiten]]
  
 
=== Recherche ===
 
=== Recherche ===
Zeile 23: Zeile 28:
 
* http://www.linux-magazin.de/Ausgaben/2010/01/Dauerlaeufer
 
* http://www.linux-magazin.de/Ausgaben/2010/01/Dauerlaeufer
  
=== Script ===
+
[[Category:Web]][[Category:Programmierung]]
 
 
'''''WIP / in development / untested'''''
 
 
 
<code>./website-copy</code>:
 
<source lang="bash">
 
#!/bin/bash
 
#
 
# script to copy websites incl. database (mysql for now) from production
 
# to test server / creating a test-site
 
#
 
# using a config file per-website
 
#
 
# using rsync
 
# mysqldump, mysql/mysqladmin (?)
 
#
 
# cem, 2016-08-29
 
#
 
#
 
#
 
# program workflow
 
#
 
# 1. read settings from config file
 
#
 
# 2. copy files using rsync
 
#
 
# 3. copy database
 
#  3.1 create new db
 
#  3.2 copy from remote
 
#
 
#
 
#
 
# $1 config file
 
 
 
# check command line argument for config file
 
 
 
if [ $# -lt 1 ]; then
 
    echo "error: config file missing"
 
    echo "usage: $0 <config-file>"
 
    exit 1
 
fi
 
 
 
if [ ! -f "$1" ]; then
 
    echo "error: file not found: $1"
 
    exit 1
 
fi
 
 
 
# import settings
 
. "$1"
 
 
 
ME=$(whoami)
 
 
 
check_exit() {
 
    # $1: exit code, $?
 
    if [ $1 -ne 0 ]; then
 
        echo "oops, something went wrong, exiting."
 
        exit 1
 
    else
 
        echo "done."
 
    fi
 
}
 
 
 
# copy files from server using rsync
 
# rsync opts
 
# -r recursive
 
# -l copy symlinks as symlinks
 
# -p preserve permissions
 
#
 
# remote path includes always a trailing slash,
 
# by `parameter substitution`, e.g.: "${var%/}"/
 
# stripping if present and readding to avoid doubles
 
#
 
echo "copying files..."
 
sudo -u "$WEBSITE_LOCAL_USER". \
 
    rsync -rlpv "$ME"@"$WEBSITE_REMOTE_SERVER":"${WEBSITE_REMOTE_PATH%/}"/ \
 
    "$WEBSITE_LOCAL_PATH"
 
check_exit $?
 
 
 
# --> must create local db first ????
 
# create new db on local instance
 
# mysql > 5.7.6
 
# for mysql below this use something like:
 
# GRANT ALL ON `database`.* TO 'user'@'localhost' IDENTIFIED BY 'password';
 
# - http://stackoverflow.com/questions/13357760/mysql-create-user-if-not-exists#
 
echo "creating local database..."
 
mysql <<EOF
 
  CREATE DATABASE IF NOT EXISTS '$DB_LOCAL_NAME';
 
  CREATE USER IF NOT EXISTS '$DB_LOCAL_USER'@'localhost'
 
    IDENTIFIED BY '$DB_LOCAL_PASS';
 
  GRANT ALL PRIVILEGES ON $DB_LOCAL_NAME.* TO '$DB_LOCAL_USER'@'localhost';
 
  FLUSH PRIVILEGES;
 
EOF
 
check_exit $?
 
 
 
# ref: http://tltech.com/info/mysql-via-ssh/
 
# mysql destdb < <(ssh sourceserver.example.com "mysqldump sourcedb")
 
# sudo ??
 
# or ssh sourceserver.example.com "mysqldump sourcedb" | mysql destdb
 
#
 
# tested: ssh rochen "mysqldump joomla_revamp_ut| gzip" > joomla_revamp_ut.dump.gz
 
# works!
 
echo "copying database from remote..."
 
ssh "$WEBSITE_REMOTE_SERVER" "mysqldump $DB_NAME | gzip -c" \
 
    | gzip -d > mysql "$DB_LOCAL_NAME"
 
check_exit $?
 
 
 
# copying files from override directory
 
echo "copying files from override directory..."
 
sudo -u "$WEBSITE_LOCAL_USER". \
 
    cp -dpr "${OVERRIDE_PATH%/}"/. "$WEBSITE_LOCAL_PATH"
 
check_exit $?
 
 
 
echo "finished!"
 
 
 
</source>
 

Aktuelle Version vom 28. Februar 2018, 16:15 Uhr

Modulares Script zum kopieren von Webseiten inkl. Datenbank. Nützlich um eine Test-Entwicklungsseite zu erstellen.

Automatische Anpassung von Joomla Config.

Script

Code on github: https://github.com/rebootl/website-copy/

Siehe auch Readme dort.

Anwendung revamp-it

Anwendung zum erstellen von Testseite auf flunder-web siehe: Intern:Revamp-it.ch_auf_flunder-web#Testseite

Anwendung auf Test-/Entwicklunsserver delfin-web. Anleitung, Beispiel: Intern:Anleitungen/Webentwicklung_auf_delfin-web#Anwendung_Script_zum_kopieren_von_Webseiten

Recherche

Google: "mysqldump over internet"