Exemplo n.º 1
0
    def test_swift_encrypted_backup_restore(self):
        bakthat.backup(self.test_file.name, "swift", password=self.password,
                       profile=self.test_profile)

        self.assertEqual(bakthat.match_filename(self.test_filename, "swift",
                                                profile=self.test_profile)
                         [0]["filename"], self.test_filename)

        # Check if stored file is encrypted
        self.assertTrue(bakthat.match_filename(self.test_filename, "swift",
                                               profile=self.test_profile)
                        [0]["is_enc"])

        bakthat.restore(self.test_filename, "swift", password=self.password)

        restored_hash = hashlib.sha1(
            open(self.test_filename).read()).hexdigest()

        self.assertEqual(self.test_hash, restored_hash)

        os.remove(self.test_filename)

        bakthat.delete(self.test_filename, "swift",
                       profile=self.test_profile)

        self.assertEqual(bakthat.match_filename(self.test_filename,
                                                "swift",
                                                profile=self.test_profile),
                         [])
Exemplo n.º 2
0
    def test_swift_encrypted_backup_restore(self):
        backup_data = bakthat.backup(self.test_file.name,
                                     "swift",
                                     password=self.password,
                                     profile=self.test_profile)

        #self.assertEqual(bakthat.match_filename(self.test_filename, "swift",
        #                                        profile=self.test_profile)
        #                 [0]["filename"], self.test_filename)

        # Check if stored file is encrypted
        #self.assertTrue(bakthat.match_filename(self.test_filename, "swift",
        #                                       profile=self.test_profile)
        #                [0]["is_enc"])

        bakthat.restore(self.test_filename,
                        "swift",
                        password=self.password,
                        profile=self.test_profile)

        restored_hash = hashlib.sha1(open(
            self.test_filename).read()).hexdigest()

        self.assertEqual(self.test_hash, restored_hash)

        os.remove(self.test_filename)

        bakthat.delete(backup_data["stored_filename"],
                       "swift",
                       profile=self.test_profile)
Exemplo n.º 3
0
    def test_s3_delete_older_than(self):
        backup_res = bakthat.backup(self.test_file.name, "s3", password="")

        self.assertEqual(bakthat.match_filename(self.test_filename, "s3")[0]["filename"],
                        self.test_filename)

        bakthat.restore(self.test_filename, "s3")
        
        restored_hash = hashlib.sha1(open(self.test_filename).read()).hexdigest()
        
        self.assertEqual(self.test_hash, restored_hash)

        os.remove(self.test_filename)

        test_deleted = bakthat.delete_older_than(self.test_filename, "1Y", "s3")

        self.assertEqual(test_deleted, [])

        time.sleep(10)

        test_deleted = bakthat.delete_older_than(self.test_filename, "9s", "s3")

        key_deleted = test_deleted[0]

        self.assertEqual(key_deleted, backup_res["stored_filename"])

        self.assertEqual(bakthat.match_filename(self.test_filename), [])
Exemplo n.º 4
0
    def test_swift_backup_restore(self):
        backup_data = bakthat.backup(self.test_file.name,
                                     "swift",
                                     password="",
                                     profile=self.test_profile)
        log.info(backup_data)

        #self.assertEqual(bakthat.match_filename(self.test_filename, "swift",
        #                                        profile=self.test_profile
        #                                        )[0]["filename"],
        #                 self.test_filename)

        sleep(5)

        bakthat.restore(self.test_filename, "swift", profile=self.test_profile)

        restored_hash = hashlib.sha1(open(
            self.test_filename).read()).hexdigest()

        self.assertEqual(self.test_hash, restored_hash)

        os.remove(self.test_filename)

        bakthat.delete(backup_data["stored_filename"],
                       "swift",
                       profile=self.test_profile)
Exemplo n.º 5
0
    def test_swift_delete_older_than(self):
        backup_res = bakthat.backup(self.test_filename, "azure", password="",
                                    profile=self.test_profile)

        #self.assertEqual(bakthat.match_filename(self.test_filename, "swift",
        #                                        profile=self.test_profile
        #                                        )[0]["filename"],
        #                 self.test_filename)

        bakthat.restore(self.test_filename, "azure",
                        profile=self.test_profile)

        restored_hash = hashlib.sha1(
            open(self.test_filename).read()).hexdigest()

        self.assertEqual(self.test_hash, restored_hash)

        #os.remove(self.test_filename)

        test_deleted = bakthat.delete_older_than(self.test_filename, "1Y",
                                                 destination="azure",
                                                 profile=self.test_profile)

        self.assertEqual(test_deleted, [])

        time.sleep(10)

        test_deleted = bakthat.delete_older_than(self.test_filename, "9s",
                                                 destination="azure",
                                                 profile=self.test_profile)

       
        key_deleted = test_deleted[0]

        self.assertEqual(key_deleted, backup_res)
Exemplo n.º 6
0
    def test_s3_delete_older_than(self):
        backup_res = bakthat.backup(self.test_file.name, "s3", password="")

        #self.assertEqual(bakthat.match_filename(self.test_filename, "s3")[0]["filename"],
        #                 self.test_filename)

        bakthat.restore(self.test_filename, "s3")

        restored_hash = hashlib.sha1(open(
            self.test_filename).read()).hexdigest()

        self.assertEqual(self.test_hash, restored_hash)

        os.remove(self.test_filename)

        test_deleted = bakthat.delete_older_than(self.test_filename,
                                                 "1Y",
                                                 destination="s3")

        self.assertEqual(test_deleted, [])

        time.sleep(10)

        test_deleted = bakthat.delete_older_than(self.test_filename,
                                                 "9s",
                                                 destination="s3")

        key_deleted = test_deleted[0]

        self.assertEqual(key_deleted.stored_filename,
                         backup_res.stored_filename)
Exemplo n.º 7
0
    def test_s3_backup_restore(self):
        bakthat.backup(self.test_file.name, "s3", password="")

        self.assertEqual(bakthat.match_filename(self.test_filename, "s3")[0]["filename"],
                        self.test_filename)

        bakthat.restore(self.test_filename, "s3")
        
        restored_hash = hashlib.sha1(open(self.test_filename).read()).hexdigest()
        
        self.assertEqual(self.test_hash, restored_hash)

        os.remove(self.test_filename)

        bakthat.delete(self.test_filename, "s3")

        self.assertEqual(bakthat.match_filename(self.test_filename), [])
Exemplo n.º 8
0
    def test_s3_encrypted_backup_restore(self):
        bakthat.backup(self.test_file.name, "s3", password=self.password)

        #self.assertEqual(bakthat.match_filename(self.test_filename, "s3")[0]["filename"],
        #                 self.test_filename)

        # Check if stored file is encrypted
        #self.assertTrue(bakthat.match_filename(self.test_filename, "s3")[0]["is_enc"])

        bakthat.restore(self.test_filename, "s3", password=self.password)

        restored_hash = hashlib.sha1(open(self.test_filename).read()).hexdigest()

        self.assertEqual(self.test_hash, restored_hash)

        os.remove(self.test_filename)

        bakthat.delete(self.test_filename, "s3")
Exemplo n.º 9
0
    def test_s3_backup_restore(self):
        backup_data = bakthat.backup(self.test_file.name, "s3", password="")
        log.info(backup_data)

        #self.assertEqual(bakthat.match_filename(self.test_filename, "s3")[0]["filename"],
        #                 self.test_filename)

        bakthat.restore(self.test_filename, "s3")

        restored_hash = hashlib.sha1(open(self.test_filename).read()).hexdigest()

        self.assertEqual(self.test_hash, restored_hash)

        os.remove(self.test_filename)

        bakthat.delete(self.test_filename, "s3")
Exemplo n.º 10
0
    def test_swift_backup_restore(self):
        backup_data = bakthat.backup(self.test_file.name, "swift", password="",
                                     profile=self.test_profile)
        log.info(backup_data)

        #self.assertEqual(bakthat.match_filename(self.test_filename, "swift",
        #                                        profile=self.test_profile
        #                                        )[0]["filename"],
        #                 self.test_filename)

        bakthat.restore(self.test_filename, "swift", profile=self.test_profile)

        restored_hash = hashlib.sha1(
            open(self.test_filename).read()).hexdigest()

        self.assertEqual(self.test_hash, restored_hash)

        os.remove(self.test_filename)

        bakthat.delete(backup_data["stored_filename"], "swift", profile=self.test_profile)
Exemplo n.º 11
0
    def test_swift_delete_older_than(self):
        backup_res = bakthat.backup(self.test_file.name,
                                    "swift",
                                    password="",
                                    profile=self.test_profile)

        #self.assertEqual(bakthat.match_filename(self.test_filename, "swift",
        #                                        profile=self.test_profile
        #                                        )[0]["filename"],
        #                 self.test_filename)

        bakthat.restore(self.test_filename, "swift", profile=self.test_profile)

        restored_hash = hashlib.sha1(open(
            self.test_filename).read()).hexdigest()

        self.assertEqual(self.test_hash, restored_hash)

        os.remove(self.test_filename)

        test_deleted = bakthat.delete_older_than(self.test_filename,
                                                 "1Y",
                                                 "swift",
                                                 profile=self.test_profile)

        self.assertEqual(test_deleted, [])

        time.sleep(10)

        test_deleted = bakthat.delete_older_than(self.test_filename,
                                                 "9s",
                                                 "swift",
                                                 profile=self.test_profile)

        key_deleted = test_deleted[0]

        self.assertEqual(key_deleted, backup_res["stored_filename"])
Exemplo n.º 12
0
    def test_glacier_backup_restore(self):
        if raw_input("Test glacier upload/download ? It can take up to 4 hours ! (y/N): ").lower() == "y":

            # Backup dummy file
            bakthat.backup(self.test_file.name, "glacier", password="")

            # Check that file is showing up in bakthat ls
            self.assertEqual(bakthat.match_filename(self.test_filename, "glacier")[0]["filename"],
                            self.test_filename)


            # We initialize glacier backend 
            # to check that the file appear in both local and remote (S3) inventory
            glacier_backend = bakthat.GlacierBackend(None)
            
            archives = glacier_backend.load_archives()
            archives_s3 = glacier_backend.load_archives_from_s3()

            # Check that local and remote custom inventory are equal
            self.assertEqual(archives, archives_s3)

            # Next we check that the file is stored in both inventories
            inventory_key_name = bakthat.match_filename(self.test_filename, "glacier")[0]["key"]

            self.assertTrue(inventory_key_name in archives)
            self.assertTrue(inventory_key_name in archives_s3)

            # Restore backup
            job = bakthat.restore(self.test_filename, "glacier", job_check=True)
            
            # Check that a job is initiated
            self.assertEqual(job.__dict__["action"], "ArchiveRetrieval")
            self.assertEqual(job.__dict__["status_code"], "InProgress")

            while 1:
                # Check every ten minutes if the job is done
                result = bakthat.restore(self.test_filename, "glacier")
                
                # If job is done, we can download the file
                if result:
                    restored_hash = hashlib.sha1(open(self.test_filename).read()).hexdigest()
        
                    # Check if the hash of the restored file is equal to inital file hash
                    self.assertEqual(self.test_hash, restored_hash)

                    os.remove(self.test_filename)

                    # Now, we can delete the restored file
                    bakthat.delete(self.test_filename, "glacier")

                    # Check that the file is deleted
                    self.assertEqual(bakthat.match_filename(self.test_filename, "glacier"), [])

                    archives = glacier_backend.load_archives()
                    archives_s3 = glacier_backend.load_archives_from_s3()

                    # Check if the file has been removed from both archives
                    self.assertEqual(archives, archives_s3) 

                    self.assertTrue(inventory_key_name not in archives)
                    self.assertTrue(inventory_key_name not in archives_s3)

                    break
                else:
                    time.sleep(600)
Exemplo n.º 13
0
    def test_glacier_backup_restore(self):
        if raw_input(
                "Test glacier upload/download ? It can take up to 4 hours ! (y/N): "
        ).lower() == "y":

            # Backup dummy file
            bakthat.backup(self.test_file.name, "glacier", password="")

            # Check that file is showing up in bakthat ls
            #self.assertEqual(bakthat.match_filename(self.test_filename, "glacier")[0]["filename"],
            #                self.test_filename)
            # TODO replace by a Backups.search

            # We initialize glacier backend
            # to check that the file appear in both local and remote (S3) inventory
            #glacier_backend = GlacierBackend(None)

            #archives = glacier_backend.load_archives()
            #archives_s3 = glacier_backend.load_archives_from_s3()

            # Check that local and remote custom inventory are equal
            #self.assertEqual(archives, archives_s3)

            # Next we check that the file is stored in both inventories
            #inventory_key_name = bakthat.match_filename(self.test_filename, "glacier")[0]["key"]

            #self.assertTrue(inventory_key_name in [a.get("filename") for a in archives])
            #self.assertTrue(inventory_key_name in [a.get("filename") for a in archives_s3])

            # Restore backup
            job = bakthat.restore(self.test_filename,
                                  "glacier",
                                  job_check=True)

            # Check that a job is initiated
            self.assertEqual(job.__dict__["action"], "ArchiveRetrieval")
            self.assertEqual(job.__dict__["status_code"], "InProgress")

            while 1:
                # Check every ten minutes if the job is done
                result = bakthat.restore(self.test_filename, "glacier")

                # If job is done, we can download the file
                if result:
                    restored_hash = hashlib.sha1(
                        open(self.test_filename).read()).hexdigest()

                    # Check if the hash of the restored file is equal to inital file hash
                    self.assertEqual(self.test_hash, restored_hash)

                    os.remove(self.test_filename)

                    # Now, we can delete the restored file
                    bakthat.delete(self.test_filename, "glacier")

                    # Check that the file is deleted
                    #self.assertEqual(bakthat.match_filename(self.test_filename, "glacier"), [])
                    # TODO Backups.search

                    #archives = glacier_backend.load_archives()
                    #archives_s3 = glacier_backend.load_archives_from_s3()

                    # Check if the file has been removed from both archives
                    #self.assertEqual(archives, archives_s3)
                    #self.assertTrue(inventory_key_name not in archives)
                    #self.assertTrue(inventory_key_name not in archives_s3)

                    break
                else:
                    time.sleep(600)