Beispiel #1
0
    def backup_cycle(self):
        lasttime = self.lastBackupTime
        now = datetime.datetime.now()

        compare_time = lasttime.replace(hour=4, minute=35, second=0, microsecond=0)
        if compare_time > lasttime:
            next_time = compare_time
        else:
            next_time = compare_time + datetime.timedelta(days=1)

        if now > next_time or self.forceBackup == True:
            self.forceBackup = False
            print 'Doing a backup (' + str(datetime.datetime.now()) + ')'
            with app.app_context():
                flask_alchemydumps.autoclean(True)
                flask_alchemydumps.create()
                if config.BACKUP_ENABLE_FTP == True:
                    print 'Doing a additional FTP backup'
                    app.config['ALCHEMYDUMPS_FTP_SERVER'] = ''
                    app.config['ALCHEMYDUMPS_FTP_USER'] = ''
                    app.config['ALCHEMYDUMPS_FTP_PASSWORD'] = ''
                    app.config['ALCHEMYDUMPS_FTP_PATH'] = ''
                    flask_alchemydumps.create()
                    app.config['ALCHEMYDUMPS_FTP_SERVER'] = config.ALCHEMYDUMPS_FTP_SERVER
                    app.config['ALCHEMYDUMPS_FTP_USER'] = config.ALCHEMYDUMPS_FTP_USER
                    app.config['ALCHEMYDUMPS_FTP_PASSWORD'] = config.ALCHEMYDUMPS_FTP_PASSWORD
                    app.config['ALCHEMYDUMPS_FTP_PATH'] = config.ALCHEMYDUMPS_FTP_PATH
            print 'Next backup @' + str(next_time) + ' (' + str(datetime.datetime.now()) + ')'
            logentry = Action(datetime.datetime.utcnow(), config.NODE_NAME, 'Sync Master',
                           '*****@*****.**', 'Backup database', 'Backup',
                           'L1', 0, 'Internal')
            db.session.add(logentry)
            db.session.commit()
            self.lastBackupTime = now
Beispiel #2
0
    def backup_cycle(self):
        lasttime = self.lastBackupTime
        now = datetime.datetime.now()

        compare_time = lasttime.replace(hour=4, minute=35, second=0, microsecond=0)
        if compare_time > lasttime:
            next_time = compare_time
        else:
            next_time = compare_time + datetime.timedelta(days=1)

        if now > next_time or self.forceBackup == True:
            self.forceBackup = False
            print 'Doing a backup (' + str(datetime.datetime.now()) + ')'
            with app.app_context():
                flask_alchemydumps.autoclean(True)
                flask_alchemydumps.create()
                if config.BACKUP_ENABLE_FTP == True:
                    print 'Doing a additional FTP backup'
                    app.config['ALCHEMYDUMPS_FTP_SERVER'] = ''
                    app.config['ALCHEMYDUMPS_FTP_USER'] = ''
                    app.config['ALCHEMYDUMPS_FTP_PASSWORD'] = ''
                    app.config['ALCHEMYDUMPS_FTP_PATH'] = ''
                    flask_alchemydumps.create()
                    app.config['ALCHEMYDUMPS_FTP_SERVER'] = config.ALCHEMYDUMPS_FTP_SERVER
                    app.config['ALCHEMYDUMPS_FTP_USER'] = config.ALCHEMYDUMPS_FTP_USER
                    app.config['ALCHEMYDUMPS_FTP_PASSWORD'] = config.ALCHEMYDUMPS_FTP_PASSWORD
                    app.config['ALCHEMYDUMPS_FTP_PATH'] = config.ALCHEMYDUMPS_FTP_PATH
            print 'Next backup @' + str(next_time) + ' (' + str(datetime.datetime.now()) + ')'
            logentry = Action(datetime.datetime.utcnow(), config.NODE_NAME, 'Sync Master',
                           '*****@*****.**', 'Backup database', 'Backup',
                           'L1', 0, 'Internal')
            db.session.add(logentry)
            db.session.commit()
            self.lastBackupTime = now
Beispiel #3
0
    def backup_cycle(self):
        lasttime = self.lastBackupTime
        now = datetime.datetime.now()

        compare_time = lasttime.replace(hour=4, minute=35, second=0, microsecond=0)
        if compare_time > lasttime:
            next_time = compare_time
        else:
            next_time = compare_time + datetime.timedelta(days=1)

        if now > next_time or self.forceBackup == True:
            self.forceBackup = False
            print "Doing a backup (" + str(datetime.datetime.now()) + ")"
            with app.app_context():
                flask_alchemydumps.autoclean(True)
                flask_alchemydumps.create()
                if config.BACKUP_ENABLE_FTP == True:
                    print "Doing a additional FTP backup"
                    app.config["ALCHEMYDUMPS_FTP_SERVER"] = ""
                    app.config["ALCHEMYDUMPS_FTP_USER"] = ""
                    app.config["ALCHEMYDUMPS_FTP_PASSWORD"] = ""
                    app.config["ALCHEMYDUMPS_FTP_PATH"] = ""
                    flask_alchemydumps.create()
                    app.config["ALCHEMYDUMPS_FTP_SERVER"] = config.ALCHEMYDUMPS_FTP_SERVER
                    app.config["ALCHEMYDUMPS_FTP_USER"] = config.ALCHEMYDUMPS_FTP_USER
                    app.config["ALCHEMYDUMPS_FTP_PASSWORD"] = config.ALCHEMYDUMPS_FTP_PASSWORD
                    app.config["ALCHEMYDUMPS_FTP_PATH"] = config.ALCHEMYDUMPS_FTP_PATH
            print "Next backup @" + str(next_time) + " (" + str(datetime.datetime.now()) + ")"
            logentry = Action(
                datetime.datetime.utcnow(),
                config.NODE_NAME,
                "Sync Master",
                "*****@*****.**",
                "Backup database",
                "Backup",
                "L1",
                0,
                "Internal",
            )
            db.session.add(logentry)
            db.session.commit()
            self.lastBackupTime = now
    def test_create_restore_remove(self, mock_path):
        mock_path.return_value = self.dir + os.sep

        with app.app_context():

            # assert data was inserted
            posts = Post.query.count()
            authors = User.query.count()
            controls = SomeControl.query.count()
            comments = Comments.query.count()
            self.assertEqual(posts, 2)
            self.assertEqual(authors, 1)
            self.assertEqual(controls, 1)
            self.assertEqual(comments, 0)

            # create and assert backup files
            # self.subprocess_run('create')
            create()
            backup = Backup()
            backup.files = backup.target.get_files()
            self.assertEqual(len(list(backup.files)), 4)

            # clean up database
            self.db.drop_all()
            self.db.create_all()

            # assert database is empty
            posts = Post.query.count()
            authors = User.query.count()
            controls = SomeControl.query.count()
            comments = Comments.query.count()
            self.assertEqual(posts, 0)
            self.assertEqual(authors, 0)
            self.assertEqual(controls, 0)
            self.assertEqual(comments, 0)

            # restore backup
            backup.files = backup.target.get_files()
            date_id = backup.get_timestamps()
            restore(date_id[0])

            # assert data was restored
            posts = Post.query.count()
            authors = User.query.count()
            controls = SomeControl.query.count()
            comments = Comments.query.count()
            self.assertEqual(posts, 2)
            self.assertEqual(authors, 1)
            self.assertEqual(controls, 1)
            self.assertEqual(comments, 0)

            # assert data is accurate
            posts = Post.query.all()
            for num in range(1):
                self.assertEqual(posts[num].author.email, '*****@*****.**')
                self.assertEqual(posts[num].title, u'Post {}'.format(num + 1))
                self.assertEqual(posts[num].content, u'Lorem ipsum...')

            # remove backup
            remove(date_id[0], True)

            # assert there is no backup left
            backup = Backup()
            backup.files = backup.target.get_files()
            self.assertEqual(len(tuple(backup.files)), 0)
Beispiel #5
0
    def test_create_restore_remove(self, mock_path):
        mock_path.return_value = self.dir + os.sep

        with app.app_context():

            # assert data was inserted
            posts = Post.query.count()
            authors = User.query.count()
            controls = SomeControl.query.count()
            comments = Comments.query.count()
            self.assertEqual(posts, 2)
            self.assertEqual(authors, 1)
            self.assertEqual(controls, 1)
            self.assertEqual(comments, 0)

            # create and assert backup files
            # self.subprocess_run('create')
            create()
            backup = Backup()
            backup.files = backup.target.get_files()
            self.assertEqual(len(list(backup.files)), 4)

            # clean up database
            self.db.drop_all()
            self.db.create_all()

            # assert database is empty
            posts = Post.query.count()
            authors = User.query.count()
            controls = SomeControl.query.count()
            comments = Comments.query.count()
            self.assertEqual(posts, 0)
            self.assertEqual(authors, 0)
            self.assertEqual(controls, 0)
            self.assertEqual(comments, 0)

            # restore backup
            backup.files = backup.target.get_files()
            date_id = backup.get_timestamps()
            restore(date_id[0])

            # assert data was restored
            posts = Post.query.count()
            authors = User.query.count()
            controls = SomeControl.query.count()
            comments = Comments.query.count()
            self.assertEqual(posts, 2)
            self.assertEqual(authors, 1)
            self.assertEqual(controls, 1)
            self.assertEqual(comments, 0)

            # assert data is accurate
            posts = Post.query.all()
            for num in range(1):
                self.assertEqual(posts[num].author.email, '*****@*****.**')
                self.assertEqual(posts[num].title, u'Post {}'.format(num + 1))
                self.assertEqual(posts[num].content, u'Lorem ipsum...')

            # remove backup
            remove(date_id[0], True)

            # assert there is no backup left
            backup = Backup()
            backup.files = backup.target.get_files()
            self.assertEqual(len(tuple(backup.files)), 0)
Beispiel #6
0
def backup():
    '''
    Backup the db
    '''
    create()
    autoclean()