Salı, Eylül 04, 2007

plesk için domain yedekleme

import zipfile
import sys, os, shutil, string

plesk_vhost_yolu = "/var/www/vhosts/"
yedeklenecek_yol = "/yedeklenecek/yol/"

class RecursiveFileIterator:
#http://www.faqts.com/knowledge_base/view.phtml/aid/6000
def __init__ (self, *rootDirs):
self.dirQueue = list (rootDirs)
self.includeDirs = None
self.fileQueue = []

def __getitem__ (self, index):
while len (self.fileQueue) == 0:
self.nextDir ()
result = self.fileQueue [0]
del self.fileQueue [0]
return result

def nextDir (self):
dir = self.dirQueue [0]   # fails with IndexError, which is fine
# for iterator interface
del self.dirQueue [0]
list = os.listdir (dir)
join = os.path.join
isdir = os.path.isdir
for basename in list:
fullPath = join (dir, basename)
if isdir (fullPath):
self.dirQueue.append (fullPath)
if self.includeDirs:
self.fileQueue.append (fullPath)
else:
self.fileQueue.append (fullPath)

domain_listesi = os.listdir(plesk_vhost_yolu)
for domain in domain_listesi:
print "%s icin yedekleme basliyor "%domain
file = zipfile.ZipFile(yedeklenecek_yol+domain+".zip", "w")
directory = plesk_vhost_yolu+domain+"/httpdocs/"

for name in RecursiveFileIterator(directory):
if os.path.isfile(name):
file.write(name, name, zipfile.ZIP_DEFLATED)

file.close()
print "%s icin yedekleme tamamlandi "%domain

Hiç yorum yok: