mysql plugin needed some work
This commit is contained in:
		
							parent
							
								
									118e1355bc
								
							
						
					
					
						commit
						68669a7fd5
					
				@ -7,6 +7,8 @@ import warnings
 | 
				
			|||||||
_mysql_ssl_re = re.compile('^ssl-(.*)$')
 | 
					_mysql_ssl_re = re.compile('^ssl-(.*)$')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# TODO: is it possible to do a pure-python dump via PyMySQL?
 | 
					# TODO: is it possible to do a pure-python dump via PyMySQL?
 | 
				
			||||||
 | 
					# TODO: add compression support? Not *that* necessary since borg has its own.
 | 
				
			||||||
 | 
					#       in fact, it's better to not do it on the dumps directly so borg can diff/delta better.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Backup(object):
 | 
					class Backup(object):
 | 
				
			||||||
    def __init__(self, dbs = None,
 | 
					    def __init__(self, dbs = None,
 | 
				
			||||||
@ -17,7 +19,7 @@ class Backup(object):
 | 
				
			|||||||
                       mysqlbin = 'mysql',
 | 
					                       mysqlbin = 'mysql',
 | 
				
			||||||
                       mysqldumpbin = 'mysqldump',
 | 
					                       mysqldumpbin = 'mysqldump',
 | 
				
			||||||
                       outdir = '~/.cache/backup/mysql'):
 | 
					                       outdir = '~/.cache/backup/mysql'):
 | 
				
			||||||
        # If dbs is None, we dump ALL databases.
 | 
					        # If dbs is None, we dump ALL databases (that the user has access to).
 | 
				
			||||||
        self.dbs = dbs
 | 
					        self.dbs = dbs
 | 
				
			||||||
        self.cfgsuffix = cfgsuffix
 | 
					        self.cfgsuffix = cfgsuffix
 | 
				
			||||||
        self.splitdumps = splitdumps
 | 
					        self.splitdumps = splitdumps
 | 
				
			||||||
@ -54,6 +56,7 @@ class Backup(object):
 | 
				
			|||||||
        return()
 | 
					        return()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def dump(self):
 | 
					    def dump(self):
 | 
				
			||||||
 | 
					        if self.splitdumps:
 | 
				
			||||||
            for db in self.dbs:
 | 
					            for db in self.dbs:
 | 
				
			||||||
                args = copy.deepcopy(self.dumpopts)
 | 
					                args = copy.deepcopy(self.dumpopts)
 | 
				
			||||||
                outfile = os.path.join(self.outdir, '{0}.sql'.format(db))
 | 
					                outfile = os.path.join(self.outdir, '{0}.sql'.format(db))
 | 
				
			||||||
@ -61,13 +64,33 @@ class Backup(object):
 | 
				
			|||||||
                    args.append('--skip-lock-tables')
 | 
					                    args.append('--skip-lock-tables')
 | 
				
			||||||
                elif db == 'mysql':
 | 
					                elif db == 'mysql':
 | 
				
			||||||
                    args.append('--flush-privileges')
 | 
					                    args.append('--flush-privileges')
 | 
				
			||||||
            out = subprocess.run([self.mysqldumpbin,
 | 
					                cmd = [self.mysqldumpbin,
 | 
				
			||||||
                                  '--result-file={0}'.format(outfile),
 | 
					                       '--result-file={0}'.format(outfile)]
 | 
				
			||||||
                                  args,
 | 
					                cmd.extend(args)
 | 
				
			||||||
                                  db],
 | 
					                cmd.append(db)
 | 
				
			||||||
 | 
					                out = subprocess.run(cmd,
 | 
				
			||||||
                                     stdout = subprocess.PIPE,
 | 
					                                     stdout = subprocess.PIPE,
 | 
				
			||||||
                                     stderr = subprocess.PIPE)
 | 
					                                     stderr = subprocess.PIPE)
 | 
				
			||||||
                if out.returncode != 0:
 | 
					                if out.returncode != 0:
 | 
				
			||||||
                    warn = ('Error dumping {0}: {1}').format(db, out.stderr.decode('utf-8').strip())
 | 
					                    warn = ('Error dumping {0}: {1}').format(db, out.stderr.decode('utf-8').strip())
 | 
				
			||||||
                    warnings.warn(warn)
 | 
					                    warnings.warn(warn)
 | 
				
			||||||
 | 
					        else:
 | 
				
			||||||
 | 
					            outfile = os.path.join(self.outdir, 'all.databases.sql')
 | 
				
			||||||
 | 
					            args = copy.deepcopy(self.dumpopts)
 | 
				
			||||||
 | 
					            args.append('--result-file={0}'.format(outfile))
 | 
				
			||||||
 | 
					            if 'information_schema' in self.dbs:
 | 
				
			||||||
 | 
					                args.append('--skip-lock-tables')
 | 
				
			||||||
 | 
					            if 'mysql' in self.dbs:
 | 
				
			||||||
 | 
					                args.append('--flush-privileges')
 | 
				
			||||||
 | 
					            args.append(['--databases'])
 | 
				
			||||||
 | 
					            cmd = [self.mysqldumpbin]
 | 
				
			||||||
 | 
					            cmd.extend(args)
 | 
				
			||||||
 | 
					            cmd.extend(self.dbs)
 | 
				
			||||||
 | 
					            out = subprocess.run(cmd,
 | 
				
			||||||
 | 
					                                 stdout = subprocess.PIPE,
 | 
				
			||||||
 | 
					                                 stderr = subprocess.PIPE)
 | 
				
			||||||
 | 
					            if out.returncode != 0:
 | 
				
			||||||
 | 
					                warn = ('Error dumping {0}: {1}').format(','.join(self.dbs),
 | 
				
			||||||
 | 
					                                                         out.stderr.decode('utf-8').strip())
 | 
				
			||||||
 | 
					                warnings.warn(warn)
 | 
				
			||||||
        return()
 | 
					        return()
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user