Commit 8bccda00 authored by Mindiell's avatar Mindiell

First commit

parents
*.sql
*.swp
drupal_6/*
drupal_7/*
#!/bin/bash
PATH_HOME="drupal_7/"
PATH_CONFIG="${PATH_HOME}sites/default/"
DB_NAME7="site7"
# Dump du contenu de la base de données
echo "Dump du contenu de la base de données"
mysqldump -u root -proot ${DB_NAME7} > /tmp/dump_7.sql
# On met le fichier de côté
mv /tmp/dump_7.sql ./dump_7.sql
#!/bin/bash
PATH_HOME="drupal_7/"
PATH_CONFIG="${PATH_HOME}sites/default/"
DB_NAME7="site7"
# Rapatriement de la dernière version de drupal
echo "Téléchargement de Drupal 7"
wget http://ftp.drupal.org/files/projects/drupal-7.34.tar.gz
echo "Extraction de l'archive"
tar -xvf drupal-7.34.tar.gz
echo "Suppression de l'ancien dossier s'il existe"
if test -d drupal_7
then
rm -rf drupal_7
fi
echo "Renommage du dossier"
mv drupal-7.34 drupal_7
echo "Préparation de la configuration"
`cp ${PATH_CONFIG}default.settings.php ${PATH_CONFIG}settings.php`
echo "Suppression de l'archive"
rm drupal-7.34.tar.gz
# Création du dossier files
`mkdir ${PATH_CONFIG}files`
# Mise en place des droits
`chmod o+w ${PATH_CONFIG}files`
# Récupération des informations de connexion à la base de données
echo "Récupération des informations de connexions à la base de données"
DB_USER=`cat drupal_6/sites/default/settings.php |grep -e '^\$db_url' |sed -r 's/[^\/]+\/\/([^:]+).*/\1/'`
DB_PWD=`cat drupal_6/sites/default/settings.php |grep -e '^\$db_url' |sed -r 's/[^\/]+[^:]+:([^@]+).*/\1/'`
DB_NAME=`cat drupal_6/sites/default/settings.php |grep -e '^\$db_url' |sed -r "s/[^@]+[^\/]+\/([^']+).*/\1/"`
echo "${DB_NAME} / ${DB_PWD}"
# On recrée la base
mysql -u root -proot -e "drop database if exists ${DB_NAME7}"
mysql -u root -proot -e "create database ${DB_NAME7}"
# On met en place les accès
echo "Mise en place des accès à la base de données"
mysql -u root -proot -e "grant all privileges on ${DB_NAME7}.* to '${DB_USER}'@'localhost'"
# Modification de la configuration pour se connecter à la base de données
DATABASE="\n
\$databases['default'] = array();\n
\n
// Main database\n
\$databases['default']['default'] = array(\n
'driver' => 'mysql',\n
'database' => '${DB_NAME7}',\n
'username' => '${DB_USER}',\n
'password' => '${DB_PWD}',\n
'host' => 'localhost',\n
'prefix' => '',\n
);\n
\n"
`echo -e ${DATABASE} >> ${PATH_CONFIG}settings.php`
#!/bin/bash
PATH_HOME="drupal_7/"
PATH_CONFIG="${PATH_HOME}sites/default/"
DB_NAME7="site7"
# Rapatriement de la dernière version de drupal
echo "Téléchargement de Drupal 7"
wget http://ftp.drupal.org/files/projects/drupal-7.34.tar.gz
echo "Extraction de l'archive"
tar -xvf drupal-7.34.tar.gz
echo "Suppression de l'ancien dossier s'il existe"
if test -d drupal_7
then
rm -rf drupal_7
fi
echo "Renommage du dossier"
mv drupal-7.34 drupal_7
echo "Préparation de la configuration"
`cp ${PATH_CONFIG}default.settings.php ${PATH_CONFIG}settings.php`
echo "Suppression de l'archive"
rm drupal-7.34.tar.gz
# Création du dossier files
`mkdir ${PATH_CONFIG}files`
# Mise en place des droits
`chmod o+w ${PATH_CONFIG}files`
# Récupération des informations de connexion à la base de données
echo "Récupération des informations de connexions à la base de données"
DB_USER=`cat drupal_6/sites/default/settings.php |grep -e '^\$db_url' |sed -r 's/[^\/]+\/\/([^:]+).*/\1/'`
DB_PWD=`cat drupal_6/sites/default/settings.php |grep -e '^\$db_url' |sed -r 's/[^\/]+[^:]+:([^@]+).*/\1/'`
DB_NAME=`cat drupal_6/sites/default/settings.php |grep -e '^\$db_url' |sed -r "s/[^@]+[^\/]+\/([^']+).*/\1/"`
echo "${DB_NAME} / ${DB_PWD}"
# On recrée la base
mysql -u root -proot -e "drop database if exists ${DB_NAME7}"
mysql -u root -proot -e "create database ${DB_NAME7}"
# On met en place les accès
echo "Mise en place des accès à la base de données"
mysql -u root -proot -e "grant all privileges on ${DB_NAME7}.* to '${DB_USER}'@'localhost'"
# Modification de la configuration pour se connecter à la base de données
DATABASE="\n
\$databases['default'] = array();\n
\n
// Main database\n
\$databases['default']['default'] = array(\n
'driver' => 'mysql',\n
'database' => '${DB_NAME7}',\n
'username' => '${DB_USER}',\n
'password' => '${DB_PWD}',\n
'host' => 'localhost',\n
'prefix' => '',\n
);\n
\n"
`echo -e ${DATABASE} >> ${PATH_CONFIG}settings.php`
#!/bin/bash
# Récupération des informations de connexion à la base de données
echo "Récupération des informations de connexions à la base de données"
DB_USER=`cat drupal_6/sites/default/settings.php |grep -e '^\$db_url' |sed -r 's/[^\/]+\/\/([^:]+).*/\1/'`
DB_PWD=`cat drupal_6/sites/default/settings.php |grep -e '^\$db_url' |sed -r 's/[^\/]+[^:]+:([^@]+).*/\1/'`
DB_NAME=`cat drupal_6/sites/default/settings.php |grep -e '^\$db_url' |sed -r "s/[^@]+[^\/]+\/([^']+).*/\1/"`
echo "${DB_NAME} / ${DB_PWD}"
# On crée la base si nécessaire
mysql -u root -proot -e "create database if not exists ${DB_NAME}"
# On réintègre la base de prod
echo "Reconstruction de la base de données"
mysql -u root -proot ${DB_NAME} < dump.sql
# On regénère l'utilisateur et on lui donne accès
echo "Remise en place des accès à la base de données"
mysql -u root -proot -e "drop user '${DB_USER}'@'localhost'"
mysql -u root -proot -e "create user '${DB_USER}'@'localhost' identified by '${DB_PWD}'"
mysql -u root -proot -e "grant all privileges on ${DB_NAME}.* to '${DB_USER}'@'localhost'"
# On fait le ménage dans les tables
mysql -u root -proot -e "TRUNCATE TABLE ${DB_NAME}.accesslog;"
mysql -u root -proot -e "TRUNCATE TABLE ${DB_NAME}.cache;"
mysql -u root -proot -e "TRUNCATE TABLE ${DB_NAME}.cache_apachesolr;"
mysql -u root -proot -e "TRUNCATE TABLE ${DB_NAME}.cache_block;"
mysql -u root -proot -e "TRUNCATE TABLE ${DB_NAME}.cache_filter;"
mysql -u root -proot -e "TRUNCATE TABLE ${DB_NAME}.cache_form;"
mysql -u root -proot -e "TRUNCATE TABLE ${DB_NAME}.cache_menu;"
mysql -u root -proot -e "TRUNCATE TABLE ${DB_NAME}.cache_page;"
mysql -u root -proot -e "TRUNCATE TABLE ${DB_NAME}.cache_update;"
mysql -u root -proot -e "TRUNCATE TABLE ${DB_NAME}.cache_views;"
mysql -u root -proot -e "TRUNCATE TABLE ${DB_NAME}.cache_views_data;"
mysql -u root -proot -e "TRUNCATE TABLE ${DB_NAME}.ctools_css_cache;"
mysql -u root -proot -e "TRUNCATE TABLE ${DB_NAME}.ctools_object_cache;"
mysql -u root -proot -e "TRUNCATE TABLE ${DB_NAME}.search_dataset;"
mysql -u root -proot -e "TRUNCATE TABLE ${DB_NAME}.search_index;"
mysql -u root -proot -e "TRUNCATE TABLE ${DB_NAME}.search_node_links;"
mysql -u root -proot -e "TRUNCATE TABLE ${DB_NAME}.search_total;"
mysql -u root -proot -e "TRUNCATE TABLE ${DB_NAME}.watchdog;"
#!/bin/bash
PATH_HOME="drupal_7/"
PATH_CONFIG="${PATH_HOME}sites/default/"
DB_NAME7="site7"
# On écrase et remplace la base de données
echo "Restauration du contenu de la base de données"
mysql -u root -proot ${DB_NAME7} < dump_7.sql
#!/bin/bash
# Rapatriement de la dernière version du site de prod
echo "Synchronisation des fichiers du site"
rsync root@tau.lqdn.fr:/var/www/site/* drupal_6 -avzP --delete --exclude=files/* --exclude=pi-billion.txt
# Modification de la configuration pour ne pas bloquer la connexion des utilisateurs
sed -r 's#(\$conf\[.session_inc)#//\1#' drupal_6/sites/default/settings.php > settings.php
chmod 755 drupal_6/sites/default
chmod +w drupal_6/sites/default/settings.php
mv settings.php drupal_6/sites/default/settings.php
chmod -w drupal_6/sites/default/settings.php
chmod 555 drupal_6/sites/default
# Récupération des informations de connexion à la base de données
echo "Récupération des informations de connexions à la base de données"
DB_USER=`cat drupal_6/sites/default/settings.php |grep -e '^\$db_url' |sed -r 's/[^\/]+\/\/([^:]+).*/\1/'`
DB_PWD=`cat drupal_6/sites/default/settings.php |grep -e '^\$db_url' |sed -r 's/[^\/]+[^:]+:([^@]+).*/\1/'`
DB_NAME=`cat drupal_6/sites/default/settings.php |grep -e '^\$db_url' |sed -r "s/[^@]+[^\/]+\/([^']+).*/\1/"`
echo "${DB_NAME} / ${DB_PWD}"
# On fait un dump de la base de données à distance
echo "Récupération de la base de données"
ssh root@tau.lqdn.fr "mysqldump ${DB_NAME} > /tmp/dump.sql"
# On supprime le fichier dump si présent
if test -f dump.sql
then
rm dump.sql
fi
# On rapatrie ce fichier
rsync -avzP root@tau.lqdn.fr:/tmp/dump.sql ./dump.sql
# On crée la base si nécessaire
mysql -u root -proot -e "create database if not exists ${DB_NAME}"
# On réintègre la base de prod
echo "Reconstruction de la base de données"
mysql -u root -proot ${DB_NAME} < dump.sql
# On regénère l'utilisateur et on lui donne accès
echo "Remise en place des accès à la base de données"
mysql -u root -proot -e "drop user '${DB_USER}'@'localhost'"
mysql -u root -proot -e "create user '${DB_USER}'@'localhost' identified by '${DB_PWD}'"
mysql -u root -proot -e "grant all privileges on ${DB_NAME}.* to '${DB_USER}'@'localhost'"
# On fait le ménage dans les tables
mysql -u root -proot -e "TRUNCATE TABLE ${DB_NAME}.accesslog;"
mysql -u root -proot -e "TRUNCATE TABLE ${DB_NAME}.cache;"
mysql -u root -proot -e "TRUNCATE TABLE ${DB_NAME}.cache_apachesolr;"
mysql -u root -proot -e "TRUNCATE TABLE ${DB_NAME}.cache_block;"
mysql -u root -proot -e "TRUNCATE TABLE ${DB_NAME}.cache_filter;"
mysql -u root -proot -e "TRUNCATE TABLE ${DB_NAME}.cache_form;"
mysql -u root -proot -e "TRUNCATE TABLE ${DB_NAME}.cache_menu;"
mysql -u root -proot -e "TRUNCATE TABLE ${DB_NAME}.cache_page;"
mysql -u root -proot -e "TRUNCATE TABLE ${DB_NAME}.cache_update;"
mysql -u root -proot -e "TRUNCATE TABLE ${DB_NAME}.cache_views;"
mysql -u root -proot -e "TRUNCATE TABLE ${DB_NAME}.cache_views_data;"
mysql -u root -proot -e "TRUNCATE TABLE ${DB_NAME}.ctools_css_cache;"
mysql -u root -proot -e "TRUNCATE TABLE ${DB_NAME}.ctools_object_cache;"
mysql -u root -proot -e "TRUNCATE TABLE ${DB_NAME}.search_dataset;"
mysql -u root -proot -e "TRUNCATE TABLE ${DB_NAME}.search_index;"
mysql -u root -proot -e "TRUNCATE TABLE ${DB_NAME}.search_node_links;"
mysql -u root -proot -e "TRUNCATE TABLE ${DB_NAME}.search_total;"
mysql -u root -proot -e "TRUNCATE TABLE ${DB_NAME}.watchdog;"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment