示例#1
0
    def list_db(self):
        if not 'name' in self.pool:
            self._args.print_help()
            exit(1)

        if go(['ls {}{} | wc -l'.format(self.pool_path, self.pool['name'])]) == '0':
            print(t.italic_yellow('There is no databases in this pool yet...'))
        else:
            print(t.blue(go(['ls {}{} | sort'.format(self.pool_path, self.pool['name'])])))
示例#2
0
    def list_backs(self):
        if self.db:
            for db in self.db:
                if go(['ls {}{}{} | sort | wc -l'.format(self.pool_path, self.pool['name'], db)]) == '0':
                    print(t.italic_yellow('There is no backups yet...'))
                else:
                    backups = go(['ls {}{}/{} | sort | nl'.format(self.pool_path, self.pool['name'], db)])
                    print(t.cyan('\n{}'.format(backups)))

                    if len(self.db) == 1:
                        return [i.split('\t')[1] for i in backups.split('\n')]
        else:
            self._args.print_help()
示例#3
0
    def cleaner(self):
        if not self.db:
            self._args.print_help()
            exit()

        print()
        for db in self.db:
            _path = self.pool_path + self.pool['name'] + '/' + db + '/'
            backups = go('ls ' + _path)
            backups = backups.split('\n')

            if len(backups) <= self.args.days:
                print(t.italic_yellow('The database ' + db + ' was already clean...'))
                continue

            ba = [datetime.strptime(x[-26:-7], '%d-%m-%YT%H:%M:%S') for x in backups]
            ba.sort()

            for x in ba[:-self.args.days]:
                target = '{}{}_{}.backup'.format(_path, db, x.strftime('%d-%m-%YT%H:%M:%S'))
                if self.pool['engine'] != 'mongodb':
                    remove(target)
                else:
                    rmtree(target)

        print(t.blue('\nDatabases cleaned...'))
示例#4
0
    def make(self):
        for db in self.db:
            db_path = self.pool_path + self.pool['name'] + '/' + db + '/'
            system('mkdir -p ' + db_path)

            status = system(self.defs['engines'][self.pool['engine']]['backup'].format(db=db, path=db_path, **self.pool))

            if not status:
                print(t.green('Successfully created backup for database:'), t.italic_green(db))
            else:
                print(t.red('Error trying to create backup for db: {}, check logs on {}'.format(db, self._log_path)))
                target = '{}{}_{}.backup'.format(db_path, db, go('date +%d-%m-%YT%H:%M:%S'))
                if path.isdir(target):
                    rmtree(target)

                if path.isfile(target):
                    remove(target)
示例#5
0
 def list_pool():
     if go(['ls ' + Backup.pool_path + ' | cut -f 1 -d "." | sort | wc -l']) == '0':
         print(t.italic_yellow('There is no pools yet...'))
     else:
         print(t.blue(go(['ls ' + Backup.pool_path + ' | grep .pkl | cut -f 1 -d "." | sort'])))
示例#6
0
#!/usr/bin/env python3

from subprocess import getoutput as go

files = go("ls")
files_used = []

for i in files.split('\n'):
    if ".ps" in i:
        files_used.append(i)

for i in files_used:
    go("ps2pdf " + i)

files = go("ls")
files_used = []

for i in files.split('\n'):
    if (".pdf" in i) and not ("ges" in i):
        files_used.append(i)

go("pdfjoin -o gesamt.pdf " + " ".join(files_used))
go("rm 0*.pdf")
示例#7
0
#!/usr/bin/env python3.7
import json, argparse
from subprocess import getoutput as go

parser = argparse.ArgumentParser()
parser.add_argument("--start_date",
                    help="Enter the start date in format year-month-day")
parser.add_argument("--end_date",
                    help="Enter the end date in format year-month-day")
args = parser.parse_args()

#Year-Month-Day
start_date = args.start_date
end_date = args.end_date

go("mkdir reports")
go("mkdir reports/%s-%s" %
   (start_date.split("-")[1], start_date.split("-")[0]))

domains = {}

instances_number = 0
for domain in go("openstack domain list -f value -c Name").split("\n"):
    domains[domain] = {}
    project_query = "openstack  project list --domain %s -f json" % domain
    print(project_query)
    for project in json.loads(go(project_query)):

        volume_query = "openstack volume list --project %s -f json" % project[
            "Name"]
        print(volume_query)
示例#8
0
def run(script_file, parameters):

    return go("./%s %s" % (script_file, parameters))