Beispiel #1
0
    def testDumpRancherDatabase(self, mock_runCmd):
        backupService = Backup()

        listDatabaseSettings = {
            "type": "mysql",
            "host": "db-host",
            "port": "3306",
            "name": "rancher",
            "user": "******",
            "password": "******"
        }

        backupService.dumpRancherDatabase('/tmp/backup', listDatabaseSettings)

        #print("Call run: %s", mock_runCmd.call_args_list)

        mock_runCmd.assert_any_call(mock.ANY, 'docker pull mysql:latest')
        mock_runCmd.assert_any_call(
            mock.ANY,
            "docker run --rm -v /tmp/backup/database:/tmp/backup/database -e 'MYSQL_PWD=password' mysql:latest sh -c 'mysqldump -h db-host -P 3306 -u user rancher > /tmp/backup/database/rancher.dump'"
        )
Beispiel #2
0
                logger.info("The dumping databases is finished.")

            # We dump the rancher stack settings if needed
            if settings['module']['stack'] is True:
                logger.info("Start to export stack as json...")
                listStacks = rancherService.getStacks()
                backupService.dumpStacksSettings(
                    settings['duplicity']['source-path'] + '/rancher',
                    listStacks)
                logger.info("The exporting of stack if finished")

            # We dump the rancher database if needed
            if settings['module']['rancher-db'] is True:
                logger.info("Start to dump Rancher database...")
                backupService.dumpRancherDatabase(
                    settings['duplicity']['source-path'] + '/rancher',
                    rancherDatabaseSettings)
                logger.info("The Rancher database dumping is finished.")

            # We run the backup
            if os.getenv("BACKUP_DUPLICITY_enable") == "true":
                logger.info(
                    "Start to externalize the backup with Duplicity...")
                backupService.runDuplicity(
                    settings['duplicity']['source-path'], backend,
                    settings['duplicity']['full-if-older-than'],
                    settings['duplicity']['remove-all-but-n-full'],
                    settings['duplicity']['remove-all-inc-of-but-n-full'],
                    settings['duplicity']['volsize'],
                    settings['duplicity']['options'],
                    settings['duplicity']['encrypt-key'])