User:Kjogi: Difference between revisions

From ICO wiki
Jump to navigationJump to search
Kjogi (talk | contribs)
Kjogi (talk | contribs)
Line 31: Line 31:
fi
fi


==Quest10.2==
=Quest10.2=


#!/usr/bin/python
#!/usr/bin/python

Revision as of 11:15, 24 May 2011

Quest10.1

<source lang="bash">

  1. !/bin/bash
  2. Autor: Kalev Jõgi
  3. Rühm: A22
  4. Versioon: 1.0
  5. Kuupäev: 20.05.2011
  1. 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

  1. Teeme varukoopia

NOW=$(date +"%d%b%y") HOST=$HOSTNAME FILENAME=$NOW"-mysql-"$HOST".sql" mysqldump --user=root --password=kalev -A > /var/varukoopiad/$FILENAME

  1. Kontrollime, kas varukoopia tegemine õnnestus, kui õnnestus,
  2. 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

  1. !/usr/bin/python
  2. -*- encoding: utf-8 -*-
  3. Autor: Kalev Jõgi
  4. Rühm: A22
  5. Versioon: 1.0
  6. Kuupäev: 24.05.2011

import os import shutil import time

sourcepath = '/var/abdata' destpath = '/var/varukoopiad' sourcefiles = os.listdir(sourcepath)

  1. Kontrollime, kas varunduskaust on olemas ja kui ei ole,
  2. siis loome selle

if os.path.exists('/var/varukoopiad'): print 'Varukoopia kaust on olemas' else: print 'Loome varukoopia kausta' os.mkdir('/var/varukoopiad')

  1. 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'

  1. 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'