def test_required_fields_set(self): database = MySQL("Some database") database.database = "test_database" self.assertEquals(database.database, "test_database") database.username = "******" self.assertEquals(database.username, "test_username") database.password = "******" self.assertEquals(database.password, "test_password")
def test_mysql_backup(self, remove, open, command_executor): database = MySQL("Some database") database.database = "test_database" database.username = "******" database.password = "******" database.destination = "/file/path.sql" self.assertFalse(open.called) database.backup() self.assertTrue(open.called) self.assertFalse(remove.called) database.cleanup() self.assertTrue(remove.called)
import datetime from paranoik.backup.providers.mysql import MySQL from paranoik.backup.providers.directory import Directory from paranoik.compress.tar import TarCompressor from paranoik.storage.s3 import S3 backup_time = datetime.datetime.now().strftime("%Y%m%d_%H%M%S") BACKUP_DIR = os.path.join("/root", "backup", backup_time) os.mkdir(BACKUP_DIR) # Backup MySQL database_file = os.path.join(BACKUP_DIR, "mysql_database.sql") database = MySQL("Redmine database") database.database = "redmine" database.username = "******" database.password = "" database.destination = database_file # All of the above could be represented as arguments of the function: # database.backup(database, username, password, destination). I think # it will be more short and comfortable. database.backup() # Backup directories srv_backup = os.path.join(BACKUP_DIR, "redmine") srv_redmine = Directory("Redmine source") srv_redmine.path = "/srv/redmine" srv_redmine.destination = srv_backup srv_redmine.backup()
def test_required_fields_not_set(self): database = MySQL("Some database") required_fields = ("database", "username", "password") for field in required_fields: self.assertRaises(ValueError, lambda: getattr(database, field))
def test_database_is_backupable(self): database = MySQL("Some database") self.assertTrue(isinstance(database, Backupable))
import datetime from paranoik.backup.providers.mysql import MySQL from paranoik.backup.providers.directory import Directory from paranoik.compress.tar import TarCompressor from paranoik.storage.s3 import S3 backup_time = datetime.datetime.now().strftime("%Y%m%d_%H%M%S") BACKUP_DIR = os.path.join("/root", "backup", backup_time) os.mkdir(BACKUP_DIR) # Backup MySQL database_file = os.path.join(BACKUP_DIR, "mysql_database.sql") database = MySQL("Redmine database") database.database = "redmine" database.username = "******" database.password = "" database.destination = database_file database.backup() # Backup directories srv_backup = os.path.join(BACKUP_DIR, "redmine") srv_redmine = Directory("Redmine source") srv_redmine.path = "/srv/redmine" srv_redmine.destination = srv_backup srv_redmine.backup() # Compress the whole backup tar_file_name = "{0}.tar.gz".format(backup_time)