Exemplo n.º 1
0
 def test_perform_backup(self):
     os.mkdir("/tmp/dummy_test_backup_dir")
     directory = Directory("Directory with images")
     directory.path = "/tmp/dummy_test_backup_dir"
     directory.destination = "/tmp/dummy_test_backup_dir_backup"
     directory.backup()
     self.assertTrue(os.path.exists("/tmp/dummy_test_backup_dir_backup"))
     os.rmdir("/tmp/dummy_test_backup_dir")
     directory.cleanup()
     self.assertFalse(os.path.exists("/tmp/dummy_test_backup_dir_backup"))
Exemplo n.º 2
0
 def test_perform_backup(self):
     os.mkdir("/tmp/dummy_test_backup_dir")
     directory = Directory("Directory with images")
     directory.path = "/tmp/dummy_test_backup_dir"
     directory.destination = "/tmp/dummy_test_backup_dir_backup"
     directory.backup()
     self.assertTrue(os.path.exists("/tmp/dummy_test_backup_dir_backup"))
     os.rmdir("/tmp/dummy_test_backup_dir")
     directory.cleanup()
     self.assertFalse(os.path.exists("/tmp/dummy_test_backup_dir_backup"))
Exemplo n.º 3
0
 def test_directory_is_backupable(self):
     directory = Directory("Some important directory")
     self.assertTrue(isinstance(directory, Backupable))
Exemplo n.º 4
0
 def test_backup_without_destination(self):
     directory = Directory("Directory with images")
     directory.path = "/tmp"
     self.assertRaises(ValueError, lambda: directory.backup())
Exemplo n.º 5
0
 def test_backup_without_path_set(self):
     directory = Directory("Some random directory")
     self.assertRaises(DirectoryBackupError, lambda: directory.backup())
Exemplo n.º 6
0
# 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()

# Compress the whole backup
tar_file_name = "{0}.tar.gz".format(backup_time)
tar_file_path = os.path.join("/root", "backup", tar_file_name)

tar = TarCompressor(tar_file_path)
tar.add(BACKUP_DIR)
tar.close()
# Here maybe it will be better to have just one method tar.compress()
# that makes everything.

# Upload to S3
Exemplo n.º 7
0
 def test_backup_without_destination(self):
     directory = Directory("Directory with images")
     directory.path = "/tmp"
     self.assertRaises(ValueError, lambda: directory.backup())
Exemplo n.º 8
0
 def test_backup_without_path_set(self):
     directory = Directory("Some random directory")
     self.assertRaises(DirectoryBackupError, lambda: directory.backup())
Exemplo n.º 9
0
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)
tar_file_path = os.path.join("/root", "backup", tar_file_name)

tar = TarCompressor(tar_file_path)
tar.add(BACKUP_DIR)
tar.close()

# Upload to S3
syncer = S3("your_access_key", "your_secret_key")
syncer.bucket = "bucket_name"