Script Webseite Duplizieren / Testseite: Unterschied zwischen den Versionen

Aus revampedia
 
(15 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'''''
 
 
 
<code>./website-copy</code>:
 
<source lang="bash">
 
#!/bin/bash
 
#
 
# script to copy websites (inkl. database) 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
 
#
 
#
 
# per-website settings
 
# --> import this from separate file later
 
 
 
# local settings
 
WEBSITE_LOCAL_PATH="/home/caydin/Scripte/website-copy/revamp_test"
 
WEBSITE_LOCAL_USER="www-data"
 
 
 
OVERRIDE_PATH="/home/caydin/Scripte/website-copy/revamp_test-ovrd"
 
 
 
DB_LOCAL_NAME="joomla_revamp_test"
 
DB_LOCAL_USER="joomlauser"
 
DB_LOCAL_PASS="secret1.x"
 
 
 
# remote settings
 
WEBSITE_REMOTE_SERVER="rochen.revamp-it.ch"
 
 
 
# (always include a trailing slash here!)
 
WEBSITE_REMOTE_PATH="/var/www/revamp/jodir_ut/"
 
 
 
DB_SERVER="rochen.revamp-it.ch"
 
DB_NAME="joomla_revamp_ut"
 
 
 
# DB LOGIN ??
 
# --> it is best to have the database login information
 
# in an sql config file, so that they don't appear on the
 
# process list !!
 
 
 
ME=$(whoami)
 
 
 
check_exit() {
 
    # $1: exit code, $?
 
    if [ $1 -ne 0 ]; then
 
        echo "oops, something went wrong, exiting."
 
        exit 1
 
    fi
 
 
 
# copy files from server using rsync
 
echo "copying files..."
 
# rsync opts
 
# -r recursive
 
# -l copy symlinks as symlinks
 
# -p preserve permissions
 
sudo -u "$WEBSITE_LOCAL_USER". \
 
    rsync -rlpv "$ME"@"$WEBSITE_REMOTE_SERVER":"$WEBSITE_REMOTE_PATH" \
 
    "$WEBSITE_LOCAL_PATH"
 
check_exit $?
 
 
 
# --> 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.g
 
z
 
# works!
 
#
 
ssh "$WEBSITE_REMOTE_SERVER" "mysqldump $DB_NAME | gzip" > mysql "$DB_LOCAL_NAME"
 
 
 
 
 
</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"