Il y a 389 articles et 19 utilisateurs inscrits (ce bandeau est défini dans MediaWiki:Sitenotice)

« Script de Backup » : différence entre les versions

De AJLSM
Aller à la navigation Aller à la recherche
m →Crontab : 2>&1 journalisation des erreurs pendant les sauvegardes
 
(4 versions intermédiaires par le même utilisateur non affichées)
Ligne 2 : Ligne 2 :


== Arborescence ==
== Arborescence ==
Le dossier {{path|./shell-scripts}} est un point de montage qui fait référence au dossier dans le {{path|{{var|$HOME}}/shell-scripts}} de l'utilisateur {{value|ajlsm}}. La procédure de mise en place du point de montage est décrite dans [[Fstab#Accès aux scripts AJLSM|Accès aux scripts AJLSM]].
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
.
./shell-scripts
├── backups
├── .ajlsm-projectsrc
├── .ajlsmrc
├── backup
│   ├── backup.README
│   ├── backup.sh
│   ├── credentials-"$PROJET"-back.sh
│   ├── credentials-"$PROJET"-front.sh
│   └── path.sh
├── .bashrc
├── flushTomcatCache.sh
├── httpd-maintenance
│   ├── maintenance.html
│   ├── maintenance.vhost.conf
│   └── README
├── installer.sh
├── logs
├── logs
├── scripts
│   └── empty.log
│  ├── backup.README
├── .projectrc
│  ├── backup.sh
├── projet-vhost.conf
│  ├── credentials-PROJET-back.sh
├── restartTomcat.sh
│  ├── credentials-PROJET-front.sh
├── toolbox.sh
│  └── path.sh
└── .zshrc
└── tmp
</syntaxhighlight>
</syntaxhighlight>
{{important|Ce script suppose une arborescence de fichiers tel que décrit dans [[Arborescence de production]]. Vous pouvez la réaliser via des liens symbolique}}
{{important|Ce script suppose une arborescence de fichiers tel que décrit dans [[Arborescence de production]]. Vous pouvez la réaliser via des liens symbolique}}
Ligne 22 : Ligne 36 :
== Adapter les variable aux projets ==
== Adapter les variable aux projets ==
Le fichiers contenants les identifiants doivent être modifier pour indiquer :
Le fichiers contenants les identifiants doivent être modifier pour indiquer :
* le nom de base postgreSQL  
* le nom de base postgreSQL
* nom d'utilisateur postgreSQL.
* nom d'utilisateur postgreSQL.
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
monProjet="ville-dole"; for i in ./scripts/*; do mv "$i" "${i/projet/$monProjet}"; done
for i in ./shell-scripts/backup/*; do mv "$i" "${i/projet/$PROJECT}"; done
</syntaxhighlight>
</syntaxhighlight>


=== Crontab ===  
=== Crontab ===
On termine par la modification du {{cmd|crontab}} pour que le script se déclenche régulièrement :
On termine par la modification du {{cmd|crontab}} pour que le script se déclenche régulièrement :
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
@daily /home/backupAgent/scripts/backup.sh ville-dole-front 2>&1 | tee -a "/home/backupAgent/logs/backup-$(date '+\%Y-\%b-\%d').log"
@daily bash /home/backupAgent/shell-scripts/backup/backup.sh ville-dole-front 2>&1 | tee -a "/home/backupAgent/logs/backup-$(date '+\%Y-\%b-\%d').log"
#@daily /home/backupAgent/scripts/backup.sh ville-dole-back 2>&1 | tee -a "/home/backupAgent/logs/backup-$(date '+\%Y-\%b-\%d').log"
#@daily bash /home/backupAgent/shell-scripts/backup/backup.sh ville-dole-back 2>&1 | tee -a "/home/backupAgent/logs/backup-$(date '+\%Y-\%b-\%d').log"
</syntaxhighlight>
</syntaxhighlight>






[[category:BASH]]
[[category:Bash]]
[[category:Sauvegarde]]
[[category:Sauvegarde]]
[[category:Doc]]
[[category:Doc]]

Dernière version du 24 avril 2013 à 10:27

Nous utilisons un utilisateur special pour gérer les tâches de sauvegarde : backupAgent. Il a son propre compte UNIX, fait parti du groupe responsable de l'application et à son propre dossier personnel, dans lequel on place les sauvegardes (scénario par défaut).

Le dossier ./shell-scripts est un point de montage qui fait référence au dossier dans le $HOME/shell-scripts de l'utilisateur ajlsm. La procédure de mise en place du point de montage est décrite dans Accès aux scripts AJLSM.

./shell-scripts
├── .ajlsm-projectsrc
├── .ajlsmrc
├── backup
│   ├── backup.README
│   ├── backup.sh
│   ├── credentials-"$PROJET"-back.sh
│   ├── credentials-"$PROJET"-front.sh
│   └── path.sh
├── .bashrc
├── flushTomcatCache.sh
├── httpd-maintenance
│   ├── maintenance.html
│   ├── maintenance.vhost.conf
│   └── README
├── installer.sh
├── logs
│   └── empty.log
├── .projectrc
├── projet-vhost.conf
├── restartTomcat.sh
├── toolbox.sh
└── .zshrc
Important :
Ce script suppose une arborescence de fichiers tel que décrit dans Arborescence de production. Vous pouvez la réaliser via des liens symbolique.
  • backup.sh: script
  • credentials-appli-recette.sh: identifiant pour l'application appli-recette
  • credentials-appli-prod.sh: identifiant pour l'application appli-prod
  • path.sh: chemin vers les ressources

Adapter les variable aux projets

[modifier | modifier le wikicode]

Le fichiers contenants les identifiants doivent être modifier pour indiquer :

  • le nom de base postgreSQL
  • nom d'utilisateur postgreSQL.
for i in ./shell-scripts/backup/*; do mv "$i" "${i/projet/$PROJECT}"; done

On termine par la modification du crontab pour que le script se déclenche régulièrement :

@daily bash /home/backupAgent/shell-scripts/backup/backup.sh ville-dole-front 2>&1 | tee -a "/home/backupAgent/logs/backup-$(date '+\%Y-\%b-\%d').log"
#@daily bash /home/backupAgent/shell-scripts/backup/backup.sh ville-dole-back 2>&1 | tee -a "/home/backupAgent/logs/backup-$(date '+\%Y-\%b-\%d').log"