contenido mirror

Gesperrt
rene04
Beiträge: 600
Registriert: Mo 10. Okt 2005, 12:28
Wohnort: Kaiserslautern
Kontaktdaten:

contenido mirror

Beitrag von rene04 »

hallo,

ich habe ja schon angekündigt, das ich ein script schreiben will welches mir folgendes möglich macht:

eine instanz auf einen neuen kunden kopieren.

im idealfall sollte man als gewissenhafter admin 2 contenido instanzen pro mandant haben. eine im live betrieb und eine für entwicklungen (oder tests). erst wenn auf der entwicklungsinstanz alles ok ist wird diese genommen und auf die liveinstanz kopiert.

leider war mir das nun etwas zuvile rumgemache jedesmal mit config.php anpassen, mandanteneinstellungen anpassen, usw.....
daher habe ich ein python buch aus dem schrank genommen und ein script geschrieben welches das alles für mich tut :)

das script ist für linux server gebaut, obs auf win funktioniert weis ich nicht.

und hier ist es, vielleicht kann es ja jemand von euch gebrauchen:

Code: Alles auswählen

#!/usr/bin/python2.4

#Imports
import os
import string

#Variablendeklaration
userLive = 'web3'
userEntwicklung = 'web4'

passLive = 'xxxxxx'
passEntwicklung = 'xxxxxx'

mandantLive = 'web3'
mandantEntwicklung = 'web4'

liveDB = 'usr_web3_1'
entwicklungsDB = 'usr_web4_1'
dumpEntwicklungsDB = '/home/%s.sql' %(mandantEntwicklung)

configLive = '/var/www/web3/html/contenido/includes/config.php'

webLive = 'www.sieda.com'
webEntwicklung = 'www.siedatest.de'

pathLive = '/var/www/web3/html/'
pathEntwicklung = '/var/www/web4/html/'

delDir = '%scms/cache' %(pathLive)

#Hauptprogramm
print '-----------------------------------------------'
print '| SEL - Contenido                             |'
print '| Spiegel Entwicklungsinstanz auf Liveinstanz |'
print '-----------------------------------------------'
print ''
print 'Starting...'
print ''
print 'Datenbankoperationen'
print '--------------------'
print 'Erstelle Datenbankdump von Entwicklungsinstanz...'

cmd = 'mysqldump -u %s -p%s %s > /home/%s.sql' %(userEntwicklung, passEntwicklung, entwicklungsDB, mandantEntwicklung)
os.popen(cmd)

print 'Loesche Livedatenbank...'

cmd = 'mysql -u %s -p%s -e "drop database %s"' %(userLive, passLive, liveDB)
os.popen(cmd)

print 'Uebernehme Entwicklungsdatenbank in Livedatenbank...'

cmd = 'mysql -u %s -p%s -e "create database %s"' %(userLive, passLive, liveDB)
os.popen(cmd)
cmd = 'mysql -u %s -p%s %s < %s' %(userLive, passLive, liveDB, dumpEntwicklungsDB)
os.popen(cmd)

print 'Datenbank uebernommen.'
print 'Passe Mandanteneinstellungen an...'

cmd = 'mysql -u %s -p%s -e "update con_clients set frontendpath=\'/var/www/%s/html/cms/\'" %s' %(userLive, passLive, mandantLive ,liveDB)
os.popen(cmd)
cmd = 'mysql -u %s -p%s -e "update con_clients set htmlpath=\'http://%s/cms/\'" %s' %(userLive, passLive, webLive ,liveDB)
os.popen(cmd)
cmd = 'mysql -u %s -p%s -e "delete * from con_code" %s' %(userLive, passLive, mandantLive)

print 'Datenbankoperationen abgeschlossen.'
print ''
print 'Dateioperationen'
print '----------------'
print 'Kopiere Dateien...'

cmd = 'cp -a %s* %s' %(pathEntwicklung, pathLive)
os.popen(cmd)

print 'Editiere ../contenido/includes/config.php...'

myfile = open(configLive, 'r+')
inhalt = myfile.read()
neuerInhalt = inhalt.replace(mandantEntwicklung, mandantLive)
neuerInhalt = neuerInhalt.replace(webEntwicklung, webLive)
myfile.close()

myfile = open(configLive, 'w+')
myfile.write(neuerInhalt)
myfile.close()

dateien = os.listdir(delDir)
for datei in dateien:
    full = os.path.join(delDir, datei)
    os.remove(full)

print 'Dateioperationen abgeschlossen.'
print ''
print 'Spiegelung der ConSolve Entwicklungsinstanz'
print 'auf die Liveinstanz erfolgreich durchgeführt.'
wenn ich auch sonst nix kann :)

ach ja, eines ist noch anzumerken. leider wird die *.htaccess nicht mitkopiert :( bin aber am schauen ob ichs net noch hinbekomm.

ach ja, die variablen müssen natürlich ans jeweilige system angepasst werden :)

gruesse rene
HerrB
Beiträge: 6935
Registriert: Do 22. Mai 2003, 12:44
Wohnort: Berlin
Kontaktdaten:

Beitrag von HerrB »

Es wäre noch ganz gut, wenn Du den DB-Prefix auch als Variable gestaltest ("con").

Gruß
HerrB
Bitte keine unaufgeforderten PMs oder E-Mails -> use da Forum!

Newsletter: V4.4.x | V4.6.0-15 (Module, Backend) | V4.6.22+
Standardartikelliste: V4.4.x | V4.6.x
http://www.contenido.org/forum/search.php | http://faq.contenido.org | http://www.communido.net
rene04
Beiträge: 600
Registriert: Mo 10. Okt 2005, 12:28
Wohnort: Kaiserslautern
Kontaktdaten:

Beitrag von rene04 »

das verstehe ich jetzt nicht. con kommt in meinem code garnicht vor. was hat es damit auf sich?

gruesse
mvf
Beiträge: 1758
Registriert: Mo 1. Aug 2005, 00:35
Wohnort: in der schönen Hallertau, mitten im Hopfen
Kontaktdaten:

Beitrag von mvf »

rene04 hat geschrieben:das verstehe ich jetzt nicht. con kommt in meinem code garnicht vor. was hat es damit auf sich?

gruesse

kommt doch z.b. hier

Code: Alles auswählen

cmd = 'mysql -u %s -p%s -e "delete * from con_code" %s' %(userLive, passLive, mandantLive) 
wobei code de tabellenname ist und con de prefix, bei manch anderem heisst diese tabelle aber vieleicht noc_code statt con_code

und so verhält es sich it allen tabellen,daher die anregungg von HerrB
Grüsse, Guido

"A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools."
Mostly Harmless - Douglas Adams
rene04
Beiträge: 600
Registriert: Mo 10. Okt 2005, 12:28
Wohnort: Kaiserslautern
Kontaktdaten:

Beitrag von rene04 »

ah ja.

Code: Alles auswählen

#!/usr/bin/python2.4

#Imports
import os
import string

#Variablendeklaration
userLive = 'web3'
userEntwicklung = 'web4'

passLive = 'xxxxxx'
passEntwicklung = 'xxxxxx'

mandantLive = 'web3'
mandantEntwicklung = 'web4'

liveDB = 'usr_web3_1'
entwicklungsDB = 'usr_web4_1'
dumpEntwicklungsDB = '/home/%s.sql' %(mandantEntwicklung)

configLive = '/var/www/web3/html/contenido/includes/config.php'

webLive = 'www.sieda.com'
webEntwicklung = 'www.siedatest.de'

pathLive = '/var/www/web3/html/'
pathEntwicklung = '/var/www/web4/html/'

delDir = '%scms/cache' %(pathLive)

tablePrefix = 'con'

#Hauptprogramm
print '-----------------------------------------------'
print '| SEL - Contenido v1.0                        |'
print '| Spiegel Entwicklungsinstanz auf Liveinstanz |'
print '| Author: Rene Rosenberger'                   |'
print '| Date: 2006-07-21                            |'
print '-----------------------------------------------'
print ''
print 'Starting...'
print ''
print 'Datenbankoperationen'
print '--------------------'
print 'Erstelle Datenbankdump von Entwicklungsinstanz...'

cmd = 'mysqldump -u %s -p%s %s > /home/%s.sql' %(userEntwicklung, passEntwicklung, entwicklungsDB, mandantEntwicklung)
os.popen(cmd)

print 'Loesche Livedatenbank...'

cmd = 'mysql -u %s -p%s -e "drop database %s"' %(userLive, passLive, liveDB)
os.popen(cmd)

print 'Uebernehme Entwicklungsdatenbank in Livedatenbank...'

cmd = 'mysql -u %s -p%s -e "create database %s"' %(userLive, passLive, liveDB)
os.popen(cmd)
cmd = 'mysql -u %s -p%s %s < %s' %(userLive, passLive, liveDB, dumpEntwicklungsDB)
os.popen(cmd)

print 'Datenbank uebernommen.'
print 'Passe Mandanteneinstellungen an...'

cmd = 'mysql -u %s -p%s -e "update %s_clients set frontendpath=\'/var/www/%s/html/cms/\'" %s' %(userLive, passLive, tablePrefix, mandantLive, liveDB)
os.popen(cmd)
cmd = 'mysql -u %s -p%s -e "update %s_clients set htmlpath=\'http://%s/cms/\'" %s' %(userLive, passLive, tablePrefix, webLive ,liveDB)
os.popen(cmd)
cmd = 'mysql -u %s -p%s -e "delete * from %s_code" %s' %(userLive, passLive, tablePrefix, mandantLive)

print 'Datenbankoperationen abgeschlossen.'
print ''
print 'Dateioperationen'
print '----------------'
print 'Kopiere Dateien...'

cmd = 'cp -a %s* %s' %(pathEntwicklung, pathLive)
os.popen(cmd)

print 'Editiere ../contenido/includes/config.php...'

myfile = open(configLive, 'r+')
inhalt = myfile.read()
neuerInhalt = inhalt.replace(mandantEntwicklung, mandantLive)
neuerInhalt = neuerInhalt.replace(webEntwicklung, webLive)
myfile.close()

myfile = open(configLive, 'w+')
myfile.write(neuerInhalt)
myfile.close()

dateien = os.listdir(delDir)
for datei in dateien:
    full = os.path.join(delDir, datei)
    os.remove(full)

print 'Dateioperationen abgeschlossen.'
print ''
print 'Spiegelung der ConSolve Entwicklungsinstanz'
print 'auf die Liveinstanz erfolgreich durchgeführt.' 
Gesperrt