コード例 #1
0
 def _remove_docker_container(self, app, args):
     if args.backup:
         if self._backup_container(app, backup_data='move') is False:
             raise Abort('Could not backup container!')
     docker = self._get_docker(app)
     if docker.container:
         Stop.call(app=app)
         docker.stop()
         docker.rm()
コード例 #2
0
	def _remove_docker_container(self, app, args):
		self._configure(app, args)
		if args.backup:
			if self._backup_container(app, remove=True) is False:
				raise RemoveBackupFailed()
		docker = self._get_docker(app)
		Stop.call(app=app)
		docker.stop()
		docker.rm()
		return True
コード例 #3
0
 def _backup_container(self, app, backup_data=False):
     docker = self._get_docker(app)
     if docker.exists():
         if not Start.call(app=app):
             self.fatal('Starting the container for %s failed' % app)
             return False
         if not self._store_data(app):
             self.fatal('Storing data for %s failed' % app)
             return False
         image_name = 'appcenter-backup-%s:%d' % (app.id, time.time())
         if backup_data == 'copy':
             shutil.copytree(app.get_data_dir(),
                             os.path.join(BACKUP_DIR, image_name, 'data'),
                             symlinks=True)
             shutil.copytree(app.get_conf_dir(),
                             os.path.join(BACKUP_DIR, image_name, 'conf'),
                             symlinks=True)
         elif backup_data == 'move':
             shutil.move(app.get_data_dir(),
                         os.path.join(BACKUP_DIR, image_name, 'data'))
             shutil.move(app.get_conf_dir(),
                         os.path.join(BACKUP_DIR, image_name, 'conf'))
         if not Stop.call(app=app):
             self.fatal('Stopping the container for %s failed' % app)
             return False
         image_id = docker.commit(image_name)
         self.log('Backed up %s as %s. ID: %s' %
                  (app, image_name, image_id))
         return image_id
     else:
         self.fatal('No container found. Unable to backup')
コード例 #4
0
    def _backup_container(self, app, backup_data=False, commit_image=True):
        docker = self._get_docker(app)
        if docker.exists():
            # New backup
            image_repo = 'appcenter-backup-%s' % app.id
            image_name = '%s:%d' % (image_repo, time.time())

            if not Start.call(app=app):
                self.fatal('Starting the container for %s failed' % app)
                return False
            if not self._store_data(app):
                self.fatal('Storing data for %s failed' % app)
                return False
            if not Stop.call(app=app):
                self.fatal('Stopping the container for %s failed' % app)
                return False

            if backup_data == 'copy':
                # not used atm
                shutil.copytree(app.get_data_dir(),
                                os.path.join(BACKUP_DIR, image_name, 'data'),
                                symlinks=True)
                shutil.copytree(app.get_conf_dir(),
                                os.path.join(BACKUP_DIR, image_name, 'conf'),
                                symlinks=True)
            elif backup_data == 'move':
                shutil.move(app.get_data_dir(),
                            os.path.join(BACKUP_DIR, image_name, 'data'))
                shutil.move(app.get_conf_dir(),
                            os.path.join(BACKUP_DIR, image_name, 'conf'))

            # Cleanup old backups
            max_number_of_backups = 1
            backed_up_dirs = glob(os.path.join(BACKUP_DIR, image_repo + ':*'))
            self.debug('Found dirs: %r' % backed_up_dirs)
            for dirname in sorted(backed_up_dirs,
                                  reverse=True)[max_number_of_backups:]:
                self.log('Removing backup %s' % dirname)
                try:
                    shutil.rmtree(dirname)
                except EnvironmentError as exc:
                    self.warn('Unable to remove backup directory: %s' % exc)
                    self.warn('Continuing anyway')
                image = os.path.basename(dirname)
                if rmi(image) != 0:
                    self.log('Unable to remove image %s' % image)
                    self.log('Probably never created')
        else:
            self.fatal('No container found. Unable to backup')
コード例 #5
0
 def _backup_container(self, app, remove=False):
     docker = self._get_docker(app)
     if docker.exists():
         if not Start.call(app=app):
             self.fatal('Starting the container for %s failed' % app)
             return False
         if not self._store_data(app):
             self.fatal('Storing data for %s failed' % app)
             return False
         if not Stop.call(app=app):
             self.fatal('Stopping the container for %s failed' % app)
             return False
         if remove:
             # New backup
             image_repo = 'appcenter-backup-%s' % app.id
             image_name = '%s:%d' % (image_repo, time.time())
             shutil.move(app.get_conf_dir(),
                         os.path.join(BACKUP_DIR, image_name, 'conf'))
     else:
         self.fatal('No container found. Unable to run store_data!')