Télécharger la présentation
La présentation est en train de télécharger. S'il vous plaît, attendez
Publié parChrestien Maitre Modifié depuis plus de 9 années
1
Master 1 ère année Sécurité des Systèmes Informatique 1 X Window Système graphique X-Window, développé au MIT dans le cadre du projet Athena Développement par Sun du système NeWS (Network Windowing System) NeWS étant un système propriétaire de Sun basé sur PostScript d'Adobe alors que X était entièrement libre, c'est ce dernier qui s'est imposé en se propageant rapidement dans le monde Unix, et en particulier dans les universités. X-Window, développé au MIT dans le cadre du projet Athena Développement par Sun du système NeWS (Network Windowing System) NeWS étant un système propriétaire de Sun basé sur PostScript d'Adobe alors que X était entièrement libre, c'est ce dernier qui s'est imposé en se propageant rapidement dans le monde Unix, et en particulier dans les universités.
2
Master 1 ère année Sécurité des Systèmes Informatique 2 X Window Système graphique X-Window du MIT (notez l'absence de "s" à Window, au contraire des produits propriétaires, comme Windows 95, OpenWindows, DECWindows), c'est: avant tout, un protocole d'affichage graphique de très bas niveau, c'est-à- dire avec des primitives simples une plateforme software (serveur) permettant cet affichage interactif sur un ensemble restreint de plateformes hardware (en principe, écran, clavier et souris à 3 boutons) Xlib, l'ensemble de fonctions de base à disposition des clients le toolkit "Xt Intrinsics", ensemble de fonctions de gestion de widgets les widgets Athena standards (Xaw) un "window manager" (twm), tout aussi standard, mais offrant un "look" un peu simple un ensemble d'applications clientes: xterm, xedit, xman, xclock… un ensemble de fichiers de configuration par défaut (.Xresources...) à l'usage de twm et des applications. X-Window du MIT (notez l'absence de "s" à Window, au contraire des produits propriétaires, comme Windows 95, OpenWindows, DECWindows), c'est: avant tout, un protocole d'affichage graphique de très bas niveau, c'est-à- dire avec des primitives simples une plateforme software (serveur) permettant cet affichage interactif sur un ensemble restreint de plateformes hardware (en principe, écran, clavier et souris à 3 boutons) Xlib, l'ensemble de fonctions de base à disposition des clients le toolkit "Xt Intrinsics", ensemble de fonctions de gestion de widgets les widgets Athena standards (Xaw) un "window manager" (twm), tout aussi standard, mais offrant un "look" un peu simple un ensemble d'applications clientes: xterm, xedit, xman, xclock… un ensemble de fichiers de configuration par défaut (.Xresources...) à l'usage de twm et des applications.
3
Master 1 ère année Sécurité des Systèmes Informatique 3 X Window Qu’est-ce que X? Environnement graphique basé sur un modèle client-serveur Le service affiche l’écran et gère les entrées utilisateur (souris, clavier, etc…) Le client est un programme qui utilise l’affichage graphique X possède son propre protocole réseau # grep X /etc/services | grep 6000 x11 6000/tcp X # the X Window System La version utilisée est X11R6 Environnement graphique basé sur un modèle client-serveur Le service affiche l’écran et gère les entrées utilisateur (souris, clavier, etc…) Le client est un programme qui utilise l’affichage graphique X possède son propre protocole réseau # grep X /etc/services | grep 6000 x11 6000/tcp X # the X Window System La version utilisée est X11R6
4
Master 1 ère année Sécurité des Systèmes Informatique 4 X Window Bibliothèques Bibliothèques qui gèrent l’affichage Xlibaccès de base Boîtes à outils (widgets) XawAthena OpenLookSun Motif QtK Desktop Environment (KDE) GtkGIMP ToolKit de GNU Network Object Model Environment (GNOME) Bibliothèques qui gèrent l’affichage Xlibaccès de base Boîtes à outils (widgets) XawAthena OpenLookSun Motif QtK Desktop Environment (KDE) GtkGIMP ToolKit de GNU Network Object Model Environment (GNOME)
5
Master 1 ère année Sécurité des Systèmes Informatique 5 X Window Bibliothèques Implémentations du standard X dans les distributions Linux XFree86Ancien standard XorgNouveau standard Les deux implémentations offrent les mêmes services. Implémentations du standard X dans les distributions Linux XFree86Ancien standard XorgNouveau standard Les deux implémentations offrent les mêmes services.
6
Master 1 ère année Sécurité des Systèmes Informatique 6 X Window Configuration xorgcfgoutil de configuration Dans les distributions Red Hat, xorgcfg est remplacé par system- config-display xorgcfgoutil de configuration Dans les distributions Red Hat, xorgcfg est remplacé par system- config-display
7
Master 1 ère année Sécurité des Systèmes Informatique 7 X Window Fichier de configuration Le fichier /etc/X11/xorg.conf Attention! Faire une sauvegarde de ce fichier avant toute modification Le fichier /etc/X11/xorg.conf Attention! Faire une sauvegarde de ce fichier avant toute modification
8
Master 1 ère année Sécurité des Systèmes Informatique 8 X Window Serveur de polices de caractères X Window propose un processus serveur de polices de caractères # service xfs status xfs (pid 2182) en cours d'exécution...GNOME Configuration # more /etc/X11/fs/config # # Default font server configuration file for Red Hat Linux # # allow a max of 10 clients to connect to this font server client-limit = 10 # when a font server reaches its limit, start up a new one clone-self = on # where to look for fonts # catalogue = /usr/X11R6/lib/X11/fonts/korean, /usr/X11R6/lib/X11/fonts/misc:unscaled, /usr/X11R6/lib/X11/fonts/75dpi:unscaled, X Window propose un processus serveur de polices de caractères # service xfs status xfs (pid 2182) en cours d'exécution...GNOME Configuration # more /etc/X11/fs/config # # Default font server configuration file for Red Hat Linux # # allow a max of 10 clients to connect to this font server client-limit = 10 # when a font server reaches its limit, start up a new one clone-self = on # where to look for fonts # catalogue = /usr/X11R6/lib/X11/fonts/korean, /usr/X11R6/lib/X11/fonts/misc:unscaled, /usr/X11R6/lib/X11/fonts/75dpi:unscaled,
9
Master 1 ère année Sécurité des Systèmes Informatique 9 X Window Serveur de polices de caractères Des polices peuvent être ajoutées Par exemple Xorg, FreeType et TrueType Vérifier si les chemins dans le fichier de configuration xfontsel Des polices peuvent être ajoutées Par exemple Xorg, FreeType et TrueType Vérifier si les chemins dans le fichier de configuration xfontsel
10
Master 1 ère année Sécurité des Systèmes Informatique 10 X Window Environnements graphiques Les gestionnaires d’affichage (Display Manager) sont des clients X qui affichent un cartouche de connexion gdmGNOME kdmKDE xdm Le gestionnaire d’affichage distributions Red Hat, xorgcfg a été remplacé par system-config-display # grep initdefault /etc/inittab # 0 - halt (Do NOT set initdefault to this) # 6 - reboot (Do NOT set initdefault to this) id:5:initdefault: Les gestionnaires d’affichage (Display Manager) sont des clients X qui affichent un cartouche de connexion gdmGNOME kdmKDE xdm Le gestionnaire d’affichage distributions Red Hat, xorgcfg a été remplacé par system-config-display # grep initdefault /etc/inittab # 0 - halt (Do NOT set initdefault to this) # 6 - reboot (Do NOT set initdefault to this) id:5:initdefault:
11
Master 1 ère année Sécurité des Systèmes Informatique 11 X Window Environnements graphiques Avec le niveau d’init 5 /etc/X11/prefdm est exécuté # grep prefdm /etc/inittab x:5:respawn:/etc/X11/prefdm -nodaemon Le script /etc/X11/prefdm lit le fichier /etc/sysconfig/desktop # more /etc/sysconfig/desktop DESKTOP="GNOME" Avec le niveau d’init 5 /etc/X11/prefdm est exécuté # grep prefdm /etc/inittab x:5:respawn:/etc/X11/prefdm -nodaemon Le script /etc/X11/prefdm lit le fichier /etc/sysconfig/desktop # more /etc/sysconfig/desktop DESKTOP="GNOME"
12
Master 1 ère année Sécurité des Systèmes Informatique 12 X Window Configuration du gestionnaire d’affichage GNOME /etc/X11/gdm/gdm.conf KDE /usr/share/config/kdm/kdmrc XDM /usr/X11R6/lib/X11/xdm/xdm- config Le répertoire peut être différent en fonction de la distribution GNOME /etc/X11/gdm/gdm.conf KDE /usr/share/config/kdm/kdmrc XDM /usr/X11R6/lib/X11/xdm/xdm- config Le répertoire peut être différent en fonction de la distribution
13
Master 1 ère année Sécurité des Systèmes Informatique 13 X Window Contrôle de plusieurs écrans X Window peut contrôler plusieurs écrans Les écrans se nomment :0.0 :0.1 X Window peut contrôler plusieurs écrans Les écrans se nomment :0.0 :0.1
14
Master 1 ère année Sécurité des Systèmes Informatique 14 X Window Prise de contrôle à distance rshremote shell rlogin telnet ssh ssh ssh –X rshremote shell rlogin telnet ssh ssh ssh –X
15
Master 1 ère année Sécurité des Systèmes Informatique 15 X Window Scripts d’administration Tcl/Tk Tcl Tool Command Language TKTool Kit Tcl/Tk Tcl Tool Command Language TKTool Kit
16
Master 1 ère année Sécurité des Systèmes Informatique 16 X Window Exemple Tcl/Tk
17
Master 1 ère année Sécurité des Systèmes Informatique 17 X Window Exemple Tcl/Tk #!/usr/bin/wish # nagios-ws.sh GUI (Graphic User Interface). # Creation date: jeu jan 25 09:32:17 CET 2007 # # Set window title wm title. "Ajouter et supprimer une machine" # Default values set realdir /root/nagios/bin set machinename poste12 set parentname switch1 set backupdir /data/backup # Recherche du site set fqdn [exec hostname -a] set host [exec hostname] set domaine [string trimleft $fqdn $host] # First frame : parameter fields frame.first -borderwidth 10 pack.first -side top -fill x label.first.machinelabel -text "Nom de la machine:" -padx 0 entry.first.srvname -width 12 -relief sunken -justify right -textvariable machinename label.first.domainlabel -text "$domaine" -padx 0 label.first.plabel -text " Nom du parent:" -padx 0 entry.first.pname -width 12 -relief sunken -justify right -textvariable parentname label.first.domainlabel2 -text "$domaine" -padx 0 pack.first.machinelabel.first.srvname.first.domainlabel -side left pack.first.plabel.first.pname.first.domainlabel2 -side left #!/usr/bin/wish # nagios-ws.sh GUI (Graphic User Interface). # Creation date: jeu jan 25 09:32:17 CET 2007 # # Set window title wm title. "Ajouter et supprimer une machine" # Default values set realdir /root/nagios/bin set machinename poste12 set parentname switch1 set backupdir /data/backup # Recherche du site set fqdn [exec hostname -a] set host [exec hostname] set domaine [string trimleft $fqdn $host] # First frame : parameter fields frame.first -borderwidth 10 pack.first -side top -fill x label.first.machinelabel -text "Nom de la machine:" -padx 0 entry.first.srvname -width 12 -relief sunken -justify right -textvariable machinename label.first.domainlabel -text "$domaine" -padx 0 label.first.plabel -text " Nom du parent:" -padx 0 entry.first.pname -width 12 -relief sunken -justify right -textvariable parentname label.first.domainlabel2 -text "$domaine" -padx 0 pack.first.machinelabel.first.srvname.first.domainlabel -side left pack.first.plabel.first.pname.first.domainlabel2 -side left
18
Master 1 ère année Sécurité des Systèmes Informatique 18 X Window Exemple Tcl/Tk # Create a frame for buttons and entry. frame.second -borderwidth 10 pack.second -side top -fill x # Create the command buttons. label.second.commandlabel -text "Commandes:" -padx 0 button.second.add -text "Ajouter" -command Add button.second.remove -text "Supprimer" -command Remove button.second.check -text "Vérifier" -command Check button.second.restart -text "Redémarrer" -command Restart pack.second.commandlabel.second.add.second.remove.second.check.second.restart -side left button.second.help -text "Aide" -command Help button.second.quit -text "Quitter" -command exit pack.second.quit.second.help -side right # Create a text widget to log the output frame.t set log [text.t.log -width 80 -height 40 \ -borderwidth 2 -relief raised -setgrid true \ -yscrollcommand {.t.scroll set}] scrollbar.t.scroll -command {.t.log yview} pack.t.scroll -side right -fill y pack.t.log -side left -fill both -expand true pack.t -side top -fill both -expand true # Create a frame for buttons and entry. frame.second -borderwidth 10 pack.second -side top -fill x # Create the command buttons. label.second.commandlabel -text "Commandes:" -padx 0 button.second.add -text "Ajouter" -command Add button.second.remove -text "Supprimer" -command Remove button.second.check -text "Vérifier" -command Check button.second.restart -text "Redémarrer" -command Restart pack.second.commandlabel.second.add.second.remove.second.check.second.restart -side left button.second.help -text "Aide" -command Help button.second.quit -text "Quitter" -command exit pack.second.quit.second.help -side right # Create a text widget to log the output frame.t set log [text.t.log -width 80 -height 40 \ -borderwidth 2 -relief raised -setgrid true \ -yscrollcommand {.t.scroll set}] scrollbar.t.scroll -command {.t.log yview} pack.t.scroll -side right -fill y pack.t.log -side left -fill both -expand true pack.t -side top -fill both -expand true
19
Master 1 ère année Sécurité des Systèmes Informatique 19 X Window Exemple Tcl/Tk # Run the program and arrange to read its input proc Run {} { global command input log machinename parentname if [catch {open "|$command |& cat"} input] { $log insert end $input\n } else { fileevent $input readable Log $log insert end $command\n } # Read and log ouput from the program proc Log {} { global input log if [eof $input] { Stop } else { gets $input line $log insert end $line\n $log see end } # Stop the program and fix up the button proc Stop {} { global input catch {close $input} } # Run the program and arrange to read its input proc Run {} { global command input log machinename parentname if [catch {open "|$command |& cat"} input] { $log insert end $input\n } else { fileevent $input readable Log $log insert end $command\n } # Read and log ouput from the program proc Log {} { global input log if [eof $input] { Stop } else { gets $input line $log insert end $line\n $log see end } # Stop the program and fix up the button proc Stop {} { global input catch {close $input} } # Add workstation proc Add {} { global realdir command machinename parentname set command "$realdir/nagios-ws.sh -ws $machinename -p $parentname add" Run } # Remove workstation proc Remove {} { global realdir command machinename parentname set command "$realdir/nagios-ws.sh -ws $machinename -p $parentname remove" Run } # Check configuration proc Check {} { global realdir command machinename parentname set command "$realdir/nagios-ws.sh -ws $machinename -p $parentname check" Run } # Service Restart proc Restart {} { global command set command "service nagios restart" Run } # Help proc Help {} { global realdir command machinename parentname set command "$realdir/nagios-ws.sh -h" Run #set command "echo nagios-ws.sh -ws $machinename -p $parentname" } # Add workstation proc Add {} { global realdir command machinename parentname set command "$realdir/nagios-ws.sh -ws $machinename -p $parentname add" Run } # Remove workstation proc Remove {} { global realdir command machinename parentname set command "$realdir/nagios-ws.sh -ws $machinename -p $parentname remove" Run } # Check configuration proc Check {} { global realdir command machinename parentname set command "$realdir/nagios-ws.sh -ws $machinename -p $parentname check" Run } # Service Restart proc Restart {} { global command set command "service nagios restart" Run } # Help proc Help {} { global realdir command machinename parentname set command "$realdir/nagios-ws.sh -h" Run #set command "echo nagios-ws.sh -ws $machinename -p $parentname" }
20
Master 1 ère année Sécurité des Systèmes Informatique 20 X Window Autre Exemple Tcl/Tk
21
Master 1 ère année Sécurité des Systèmes Informatique 21 X Window Autre Exemple Tcl/Tk #!/usr/bin/wish # db.sh GUI (Graphic User Interface). # $Id$ # Set window title wm title. "Save & Restore Database" # Default values set servername localhost set databasename NomBase set username NomUtilisateur set backupdir /data/backup # First frame : parameter fields frame.first -borderwidth 10 pack.first -side top -fill x label.first.srvlabel -text "Server Name:" -padx 0 entry.first.srvname -width 17 -relief sunken - textvariable servername label.first.dblabel -text " Database Name:" - padx 0 entry.first.dbname -width 17 -relief sunken - textvariable databasename label.first.usrlabel -text " User Name:" -padx 0 entry.first.usrname -width 17 -relief sunken - textvariable username pack.first.srvlabel.first.srvname -side left pack.first.dblabel.first.dbname -side left pack.first.usrlabel.first.usrname -side left #!/usr/bin/wish # db.sh GUI (Graphic User Interface). # $Id$ # Set window title wm title. "Save & Restore Database" # Default values set servername localhost set databasename NomBase set username NomUtilisateur set backupdir /data/backup # First frame : parameter fields frame.first -borderwidth 10 pack.first -side top -fill x label.first.srvlabel -text "Server Name:" -padx 0 entry.first.srvname -width 17 -relief sunken - textvariable servername label.first.dblabel -text " Database Name:" - padx 0 entry.first.dbname -width 17 -relief sunken - textvariable databasename label.first.usrlabel -text " User Name:" -padx 0 entry.first.usrname -width 17 -relief sunken - textvariable username pack.first.srvlabel.first.srvname -side left pack.first.dblabel.first.dbname -side left pack.first.usrlabel.first.usrname -side left # Create a frame for chosing backup file. frame.second -borderwidth 10 pack.second -side top -fill x label.second.filenamelabel -text "File name:" -padx 0 pack.second.filenamelabel -side left button.second.choosefile -text "Choose file" -command Choose pack.second.choosefile -side right entry.second.cmd -width 20 -relief sunken -textvariable filename pack.second.cmd -side left -fill x -expand true # Create a frame for buttons and entry. frame.third -borderwidth 10 pack.third -side top -fill x # Create the command buttons. label.third.databaselabel -text "Database commands:" -padx 0 button.third.save -text "Save" -command Save button.third.restore -text "Restore" -command Restore button.third.stop -text "Stop" -command StopDatabase pack.third.databaselabel.third.save.third.restore -side left button.third.help -text Help -command Help button.third.quit -text Quit -command exit pack.third.quit.third.help -side right # Create a text widget to log the output frame.t set log [text.t.log -width 80 -height 40 \ -borderwidth 2 -relief raised -setgrid true \ -yscrollcommand {.t.scroll set}] scrollbar.t.scroll -command {.t.log yview} pack.t.scroll -side right -fill y pack.t.log -side left -fill both -expand true pack.t -side top -fill both -expand true # Create a frame for chosing backup file. frame.second -borderwidth 10 pack.second -side top -fill x label.second.filenamelabel -text "File name:" -padx 0 pack.second.filenamelabel -side left button.second.choosefile -text "Choose file" -command Choose pack.second.choosefile -side right entry.second.cmd -width 20 -relief sunken -textvariable filename pack.second.cmd -side left -fill x -expand true # Create a frame for buttons and entry. frame.third -borderwidth 10 pack.third -side top -fill x # Create the command buttons. label.third.databaselabel -text "Database commands:" -padx 0 button.third.save -text "Save" -command Save button.third.restore -text "Restore" -command Restore button.third.stop -text "Stop" -command StopDatabase pack.third.databaselabel.third.save.third.restore -side left button.third.help -text Help -command Help button.third.quit -text Quit -command exit pack.third.quit.third.help -side right # Create a text widget to log the output frame.t set log [text.t.log -width 80 -height 40 \ -borderwidth 2 -relief raised -setgrid true \ -yscrollcommand {.t.scroll set}] scrollbar.t.scroll -command {.t.log yview} pack.t.scroll -side right -fill y pack.t.log -side left -fill both -expand true pack.t -side top -fill both -expand true
22
Master 1 ère année Sécurité des Systèmes Informatique 22 X Window Autre Exemple Tcl/Tk # Run the program and arrange to read its input proc Run {} { global command input log servername databasename username if [catch {open "|$command |& cat"} input] { $log insert end $input\n } else { fileevent $input readable Log $log insert end $command\n } # Read and log ouput from the program proc Log {} { global input log if [eof $input] { Stop } else { gets $input line $log insert end $line\n $log see end } # Stop the program and fix up the button proc Stop {} { global input catch {close $input} } # Run the program and arrange to read its input proc Run {} { global command input log servername databasename username if [catch {open "|$command |& cat"} input] { $log insert end $input\n } else { fileevent $input readable Log $log insert end $command\n } # Read and log ouput from the program proc Log {} { global input log if [eof $input] { Stop } else { gets $input line $log insert end $line\n $log see end } # Stop the program and fix up the button proc Stop {} { global input catch {close $input} } # Choose file proc Choose {} { global filename backupdir set directory "/data/backup" set types { {{Backup Files}{.backup}} {{All Files}*} } set filename [tk_getOpenFile -initialdir $backupdir - filetypes $types] } # Save database proc Save {} { global command servername databasename username set command "db.sh -srv $servername -db $databasename -usr $username save" Run } # Restore database proc Restore {} { global command servername databasename username filename if {$filename != ""} { set command "db.sh -srv $servername -db $databasename -usr $username -file $filename restore" Run } # Stop database proc StopDatabase {} { global command servername set command "ssh root@$servername service postgresql status" Run } # Help proc Help {} { global command set command "db.sh -help" Run } # # Choose file proc Choose {} { global filename backupdir set directory "/data/backup" set types { {{Backup Files}{.backup}} {{All Files}*} } set filename [tk_getOpenFile -initialdir $backupdir - filetypes $types] } # Save database proc Save {} { global command servername databasename username set command "db.sh -srv $servername -db $databasename -usr $username save" Run } # Restore database proc Restore {} { global command servername databasename username filename if {$filename != ""} { set command "db.sh -srv $servername -db $databasename -usr $username -file $filename restore" Run } # Stop database proc StopDatabase {} { global command servername set command "ssh root@$servername service postgresql status" Run } # Help proc Help {} { global command set command "db.sh -help" Run } #
23
Master 1 ère année Sécurité des Systèmes Informatique 23 Exemple shell #!/bin/sh # # Save databases # PROGNAME=`basename $0` SYNTAXE="Usage : $PROGNAME [-srv ] [-db ] [-file ] [-usr ] save | restore" EXAMPLE1="db.sh -db jabberd2 -srv srv54 -usr jabberd2 -file 20060216-15:01:42.backup restore" EXAMPLE2="db.sh -db jabberd2 -srv srv54 -usr jabberd2 save" # Initialisation DBSRV=database1 DBNAME=NomDeLaBase DBUSER=NomUtilisateur HEURE=`date +%Y%m%d-%T` BACKUPDIR=/data/backup PGBINDIR=/exe/pgsql/bin restore() { if [ ! -f $BACKUPFILE ]; then echo "$BACKUPFILE file doesn't exist!..." fi #!/bin/sh # # Save databases # PROGNAME=`basename $0` SYNTAXE="Usage : $PROGNAME [-srv ] [-db ] [-file ] [-usr ] save | restore" EXAMPLE1="db.sh -db jabberd2 -srv srv54 -usr jabberd2 -file 20060216-15:01:42.backup restore" EXAMPLE2="db.sh -db jabberd2 -srv srv54 -usr jabberd2 save" # Initialisation DBSRV=database1 DBNAME=NomDeLaBase DBUSER=NomUtilisateur HEURE=`date +%Y%m%d-%T` BACKUPDIR=/data/backup PGBINDIR=/exe/pgsql/bin restore() { if [ ! -f $BACKUPFILE ]; then echo "$BACKUPFILE file doesn't exist!..." fi echo "Deleting database..." $PGBINDIR/dropdb -h $DBSRV -p 5432 -U $DBUSER $DBNAME STATUS=$? if [ $STATUS = 0 ]; then echo "Database deleted" else echo "ERROR CODE: $STATUS" echo "The database is not restored" exit $STATUS fi echo "Creating new database..." $PGBINDIR/createdb -h $DBSRV -p 5432 -U $DBUSER $DBNAME STATUS=$? if [ $STATUS = 0 ]; then echo "Empty database created" else echo "ERROR CODE: $STATUS" echo "The new empty database is not created" exit $STATUS fi echo "Restoring $BACKUPFILE file in new database..." $PGBINDIR/pg_restore -i -h $DBSRV -p 5432 -U $DBUSER -d $DBNAME -v "$BACKUPFILE" STATUS=$? if [ $STATUS = 0 ]; then echo "Database restored" else echo "The database is not restored" fi exit $STATUS } echo "Deleting database..." $PGBINDIR/dropdb -h $DBSRV -p 5432 -U $DBUSER $DBNAME STATUS=$? if [ $STATUS = 0 ]; then echo "Database deleted" else echo "ERROR CODE: $STATUS" echo "The database is not restored" exit $STATUS fi echo "Creating new database..." $PGBINDIR/createdb -h $DBSRV -p 5432 -U $DBUSER $DBNAME STATUS=$? if [ $STATUS = 0 ]; then echo "Empty database created" else echo "ERROR CODE: $STATUS" echo "The new empty database is not created" exit $STATUS fi echo "Restoring $BACKUPFILE file in new database..." $PGBINDIR/pg_restore -i -h $DBSRV -p 5432 -U $DBUSER -d $DBNAME -v "$BACKUPFILE" STATUS=$? if [ $STATUS = 0 ]; then echo "Database restored" else echo "The database is not restored" fi exit $STATUS }
24
Master 1 ère année Sécurité des Systèmes Informatique 24 Exemple shell save() { BACKUPFILE=${BACKUPFILE:=$BACKUPDIR/$HEURE-$DBSRV- $DBNAME.backup} echo "Saving database..." if [ ! -d "$BACKUPDIR" ]; then mkdir -p $BACKUPDIR fi $PGBINDIR/pg_dump -i -h $DBSRV -p 5432 -U $DBUSER -F c -b -v -f "$BACKUPFILE" $DBNAME STATUS=$? if [ $STATUS = 0 ]; then echo "Database saved" else echo "The database is not saved" fi exit $STATUS } while [ $# -gt 0 ] do case "$1" in -h | -help ) echo $SYNTAXE echo $EXAMPLE1 echo $EXAMPLE2 exit 0 ;; save() { BACKUPFILE=${BACKUPFILE:=$BACKUPDIR/$HEURE-$DBSRV- $DBNAME.backup} echo "Saving database..." if [ ! -d "$BACKUPDIR" ]; then mkdir -p $BACKUPDIR fi $PGBINDIR/pg_dump -i -h $DBSRV -p 5432 -U $DBUSER -F c -b -v -f "$BACKUPFILE" $DBNAME STATUS=$? if [ $STATUS = 0 ]; then echo "Database saved" else echo "The database is not saved" fi exit $STATUS } while [ $# -gt 0 ] do case "$1" in -h | -help ) echo $SYNTAXE echo $EXAMPLE1 echo $EXAMPLE2 exit 0 ;; -db ) shift DBNAME=$1 shift ;; -file ) shift BACKUPFILE=$1 shift ;; -srv ) shift DBSRV=$1 shift ;; -usr ) shift DBUSER=$1 shift ;; * ) # Fonctions case "$1" in save | restore) FUNCTION=$1 $FUNCTION ;; *) echo $SYNTAXE echo $EXAMPLE exit 1 esac echo $SYNTAXE exit 1 ;; esac done -db ) shift DBNAME=$1 shift ;; -file ) shift BACKUPFILE=$1 shift ;; -srv ) shift DBSRV=$1 shift ;; -usr ) shift DBUSER=$1 shift ;; * ) # Fonctions case "$1" in save | restore) FUNCTION=$1 $FUNCTION ;; *) echo $SYNTAXE echo $EXAMPLE exit 1 esac echo $SYNTAXE exit 1 ;; esac done
Présentations similaires
© 2024 SlidePlayer.fr Inc.
All rights reserved.