Commits

Anonymous committed 10a5a02 Merge

merge filter

  • Participants
  • Parent commits 3a69d1f, 76b7f47

Comments (0)

Files changed (1)

File pymysqlbackuper.py

 import datetime
 import os
 
-MAXDAYS = 14 # max age of backups
+MAXDAYS = 4 # max age of backups
 LOCALSTORAGE = 'local'
 DBHOST = 'localhost'
 DBUSER = 'root'
 DBPASS = ''
 
+FILTER = ('information_schema', 'mysql')
+
 SERVERS = (
 		{
 		    'host': 'somehost1.com', # FTP hostname
 		},
 	)
 
+MAXDAYS = MAXDAYS * 24* 60 * 60
 if DBPASS:
     DBPASS = '-p%s' % DBPASS
-MAXDAYS = MAXDAYS * 24* 60 * 60
 
 class Backup:
     def __init__(self):
         self.clean()
 
     def makeBackup(self):
-        commands.getoutput("for i in `mysql -h %(host)s -u %(user)s %(pass)s -e'show databases;' | grep -v information_schema | grep -v Database | grep -v mysql`; do mysqldump  -h %(host)s -u %(user)s %(pass)s $i > %(dir)s-$i; gzip %(dir)s-$i;done" % {
-                    'host': DBHOST, 
-                    'user': DBUSER, 
-                    'pass': DBPASS,
-                    'dir': os.path.realpath('%s/%s' % (LOCALSTORAGE, self.datetime))
-                }
-            )
+        for db in self.getDatabaseList():
+            commands.getoutput("mysqldump  -h %(host)s -u %(user)s %(pass)s $i > %(dir)s-%(db)s; gzip %(dir)s-%(db)s -f" % {
+                        'host': DBHOST, 
+                        'user': DBUSER, 
+                        'pass': DBPASS,
+                        'dir': os.path.realpath('%s/%s' % (LOCALSTORAGE, self.datetime)),
+                        'db': db
+                    }
+                )
 
     def getDatabaseList(self):
         databases = commands.getoutput("mysql -h %s -u %s %s -e'show databases;' | grep -v Database" % (
                     DBPASS
                 )
             ).split()
-        return databases
+        return ('blog', )
+        return filter(lambda x: x not in FILTER, databases)
 
     def remote(self, server):
         try:
 
     def upload(self, dbname):
         filename = '%s-%s.gz' % (self.datetime, dbname)
-        self.ftp.storbinary("STOR %s" % filename, open('%s%s' % (LOCALSTORAGE, filename), 'rb'), 1024)
+        self.ftp.storbinary("STOR %s" % filename, open(os.path.realpath('%s/%s' % (LOCALSTORAGE, filename)), 'rb'), 1024)
 
-a = Backup()
+if __name__ == "__main__":
+    a = Backup()