Пример #1
0
def backup_container():
    """
    Verify the form to backup a container
    """
    if request.method == 'POST':
        container = request.form['orig']
        sr_type = request.form['dest']
        if 'push' in request.form:
            push = request.form['push']
        else:
            push = False
        sr_path = None
        for sr in storage_repos:
            if sr_type in sr:
                sr_path = sr[1]
                break

        backup_failed = True

        try:
            backup_file = lxc.backup(container=container,
                                     sr_type=sr_type,
                                     destination=sr_path)
            bucket_token = get_bucket_token(container)
            if push and bucket_token and USE_BUCKET:
                os.system('curl http://{}:{}/{} -F file=@{}'.format(
                    BUCKET_HOST, BUCKET_PORT, bucket_token, backup_file))
            backup_failed = False
        except lxc.ContainerDoesntExists:
            flash(u'The Container %s does not exist !' % container, 'error')
        except lxc.DirectoryDoesntExists:
            flash(u'Local backup directory "%s" does not exist !' % sr_path,
                  'error')
        except lxc.NFSDirectoryNotMounted:
            flash(u'NFS repository "%s" not mounted !' % sr_path, 'error')
        except subprocess.CalledProcessError:
            flash(u'Error during transfert !', 'error')
        except:
            flash(u'Error during transfert !', 'error')

        if backup_failed is not True:
            flash(u'Container %s backed up successfully' % container,
                  'success')
        else:
            flash(u'Failed to backup %s container' % container, 'error')

    return redirect(url_for('main.home'))
Пример #2
0
def backup_container():
    """
    Verify the form to backup a container
    """
    if request.method == "POST":
        container = request.form["orig"]
        sr_type = request.form["dest"]
        if "push" in request.form:
            push = request.form["push"]
        else:
            push = False
        sr_path = None
        for sr in storage_repos:
            if sr_type in sr:
                sr_path = sr[1]
                break

        backup_failed = True

        try:
            backup_file = lxc.backup(container=container, sr_type=sr_type, destination=sr_path)
            bucket_token = get_bucket_token(container)
            if push and bucket_token and USE_BUCKET:
                os.system(
                    "curl http://{}:{}/{} -F file=@{}".format(BUCKET_HOST, BUCKET_PORT, bucket_token, backup_file)
                )
            backup_failed = False
        except lxc.ContainerDoesntExists:
            flash(u"The Container %s does not exist !" % container, "error")
        except lxc.DirectoryDoesntExists:
            flash(u'Local backup directory "%s" does not exist !' % sr_path, "error")
        except lxc.NFSDirectoryNotMounted:
            flash(u'NFS repository "%s" not mounted !' % sr_path, "error")
        except subprocess.CalledProcessError:
            flash(u"Error during transfert !", "error")
        except:
            flash(u"Error during transfert !", "error")

        if backup_failed is not True:
            flash(u"Container %s backed up successfully" % container, "success")
        else:
            flash(u"Failed to backup %s container" % container, "error")

    return redirect(url_for("main.home"))
Пример #3
0
def backup_container():
    """
    Verify the form to backup a container
    """
    if request.method == 'POST':
        container = request.form['orig']
        sr_type = request.form['dest']
        if 'push' in request.form:
            push = request.form['push']
        else:
            push = False
        sr_path = None
        for sr in storage_repos:
            if sr_type in sr:
                sr_path = sr[1]
                break

        backup_failed = True

        try:
            backup_file = lxc.backup(container=container, sr_type=sr_type, destination=sr_path)
            bucket_token = get_bucket_token(container)
            if push and bucket_token and USE_BUCKET:
                    os.system('curl http://{}:{}/{} -F file=@{}'.format(BUCKET_HOST, BUCKET_PORT, bucket_token, backup_file))
            backup_failed = False
        except lxc.ContainerDoesntExists:
            flash(u'The Container %s does not exist !' % container, 'error')
        except lxc.DirectoryDoesntExists:
            flash(u'Local backup directory "%s" does not exist !' % sr_path, 'error')
        except lxc.NFSDirectoryNotMounted:
            flash(u'NFS repository "%s" not mounted !' % sr_path, 'error')
        except subprocess.CalledProcessError:
            flash(u'Error during transfert !', 'error')
        except:
            flash(u'Error during transfert !', 'error')

        if backup_failed is not True:
            flash(u'Container %s backed up successfully' % container, 'success')
        else:
            flash(u'Failed to backup %s container' % container, 'error')

    return redirect(url_for('main.home'))
Пример #4
0
    def backup_container(self):
        """
        Verify the form to backup a container.
        """
        if self.request.method == 'POST':
            container = self.request.POST['orig']
            sr_type = self.request.POST['dest']
            push = self.request.POST['push']
            sr_path = None
            for sr in self.settings['storage_repos']:
                if sr_type in sr:
                    sr_path = sr[1]
                    break

            out = None

            try:
                backup_file = lxc.backup(container=container, sr_type=sr_type, destination=sr_path)
                bucket_token = get_bucket_token(container)
                if push and bucket_token and self.settings['buckets.enabled']:
                    os.system('curl http://{}:{}/{} -F file=@{}'.format(self.settings['buckets.host'], self.settings['buckets.port'], bucket_token, backup_file))
            except lxc.ContainerDoesNotExist:
                self.session.flash('The Container {} does not exist'.format(container), queue='error')
            except lxc.DirectoryDoesNotExist:
                self.session.flash('Local backup directory "{}" does not exist'.format(sr_path), queue='error')
            except lxc.NFSDirectoryNotMounted:
                self.session.flash('NFS repository "{}" not mounted'.format(sr_path), queue='error')
            except subprocess.CalledProcessError:
                self.session.flash('Error during transfer', queue='error')
            except:
                # TODO: do we really need this unchecked exception?
                self.session.flash('Error during transfer', queue='error')

            if out == 0:
                self.session.flash('Container {} backed up successfully'.format(container), queue='success')
            elif out != 0:
                self.session.flash('Failed to backup {} container'.format(container), queue='error')

        return HTTPFound(location=self.request.route_path('home'))