User:Kjogi: Difference between revisions
Line 1: | Line 1: | ||
==Quest10.1== | ==Quest10.1== | ||
<source lang="bash"> | <source lang="bash"> | ||
#!/bin/bash | #!/bin/bash | ||
Line 29: | Line 31: | ||
echo "Varukoopia tegemine ei õnnestunud" | echo "Varukoopia tegemine ei õnnestunud" | ||
fi | fi | ||
==Quest10.2== | |||
#!/usr/bin/python | |||
#-*- encoding: utf-8 -*- | |||
#Autor: Kalev Jõgi | |||
#Rühm: A22 | |||
#Versioon: 1.0 | |||
#Kuupäev: 24.05.2011 | |||
import os | |||
import shutil | |||
import time | |||
sourcepath = '/var/abdata' | |||
destpath = '/var/varukoopiad' | |||
sourcefiles = os.listdir(sourcepath) | |||
#Kontrollime, kas varunduskaust on olemas ja kui ei ole, | |||
#siis loome selle | |||
if os.path.exists('/var/varukoopiad'): | |||
print 'Varukoopia kaust on olemas' | |||
else: | |||
print 'Loome varukoopia kausta' | |||
os.mkdir('/var/varukoopiad') | |||
#Kopeerime varukoopiafailid AB serverist Varundusserverisse | |||
for filename in sourcefiles: | |||
fullfilename = os.path.join(sourcepath, filename) | |||
if (os.path.isfile(fullfilename)): | |||
shutil.copy(fullfilename, destpath) | |||
print 'Varukoopiad AB serverist varundusserverisse kopeeritud' | |||
#Kustutame AB serverist varukoopiad, mis on vanemad kui 1 kuu | |||
now = time.time() | |||
for fname in sourcefiles: | |||
ffname = os.path.join(sourcepath, fname) | |||
if os.stat(ffname).st_mtime < now - 30 * 86400: | |||
if os.path.isfile(f): | |||
os.remove(ffname) | |||
print 'Vanad varukoopiad kustutatud' |
Revision as of 11:02, 24 May 2011
Quest10.1
<source lang="bash">
- !/bin/bash
- Autor: Kalev Jõgi
- Rühm: A22
- Versioon: 1.0
- Kuupäev: 20.05.2011
- Kontrollime, kas varunduse kaust on olemas, kui pole, siis loome
if [ -e /var/varukoopiad ]; then
echo "Varukoopiate kataloog on olemas"
else
echo "Loome varukoopiate kataloogi" mkdir /var/varukoopiad
fi
- Teeme varukoopia
NOW=$(date +"%d%b%y") HOST=$HOSTNAME FILENAME=$NOW"-mysql-"$HOST".sql" mysqldump --user=root --password=kalev -A > /var/varukoopiad/$FILENAME
- Kontrollime, kas varukoopia tegemine õnnestus, kui õnnestus,
- siis pakime koopiafaili kokku
if [ -e /var/varukoopiad/$FILENAME ]; then
echo "Varukoopia tegemine õnnestus" gzip /var/varukoopiad/$FILENAME
else
echo "Varukoopia tegemine ei õnnestunud"
fi
Quest10.2
- !/usr/bin/python
- -*- encoding: utf-8 -*-
- Autor: Kalev Jõgi
- Rühm: A22
- Versioon: 1.0
- Kuupäev: 24.05.2011
import os import shutil import time
sourcepath = '/var/abdata' destpath = '/var/varukoopiad' sourcefiles = os.listdir(sourcepath)
- Kontrollime, kas varunduskaust on olemas ja kui ei ole,
- siis loome selle
if os.path.exists('/var/varukoopiad'): print 'Varukoopia kaust on olemas' else: print 'Loome varukoopia kausta' os.mkdir('/var/varukoopiad')
- Kopeerime varukoopiafailid AB serverist Varundusserverisse
for filename in sourcefiles: fullfilename = os.path.join(sourcepath, filename) if (os.path.isfile(fullfilename)): shutil.copy(fullfilename, destpath) print 'Varukoopiad AB serverist varundusserverisse kopeeritud'
- Kustutame AB serverist varukoopiad, mis on vanemad kui 1 kuu
now = time.time() for fname in sourcefiles: ffname = os.path.join(sourcepath, fname) if os.stat(ffname).st_mtime < now - 30 * 86400: if os.path.isfile(f): os.remove(ffname) print 'Vanad varukoopiad kustutatud'