def job():
    print('Backup working...')
    filestamp = time.strftime('%Y-%m-%dT%H-%M-%S.%z')
    database_remote = (((database + '_') + filestamp) + '.bak.sql')
    PASS = ('set PGPASSWORD=%s' % password)
    os.system((('(cd backup) && (' + PASS) + (') && (pg_dump -h %s -p %s -U %s -f %s -C -d %s)' % (host, port, user, database_remote, database))))
    print(('Database dumped to ' + database_remote))
    ssh_client = paramiko.SSHClient()
    ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    ssh_client.connect(hostname='192.168.126.2', username='vmwin10', password='vmwin10')
    ftp_client = ssh_client.open_sftp()
    ftp_client.put((local_dir + database_remote), (remote_dir + database_remote))
    ftp_client.close()
    print('Successfull Backup')
    msg = EmailMessage()
    msg.set_content("Un backup vient d'etre effectue")
    msg['Subject'] = 'Email de Backup'
    msg['From'] = 'example@example.com'
    msg['To'] = 'example@example.com'
    context = ssl.create_default_context()
    with smtplib.SMTP('smtp.gmail.com', port=587) as smtp:
        smtp.starttls(context=context)
        smtp.login(msg['From'], 'password')
        smtp.send_message(msg)
def job():
    print('Backup working...')
    filestamp = time.strftime('%Y-%m-%dT%H-%M-%S.%z')
    database_remote = (((database + '_') + filestamp) + '.bak.sql')
    PASS = ('set PGPASSWORD=%s' % password)
    os.system((('(cd backup) && (' + PASS) + (') && (pg_dump -h %s -p %s -U %s -f %s -C -d %s)' % (host, port, user, database_remote, database))))
    print(('Database dumped to ' + database_remote))
    ssh_client = paramiko.SSHClient()
    ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    ssh_client.connect(hostname='192.168.126.2', username='vmwin10', password='vmwin10')
    ftp_client = ssh_client.open_sftp()
    ftp_client.put((local_dir + database_remote), (remote_dir + database_remote))
    ftp_client.close()
    print('Successfull Backup')
    msg = EmailMessage()
    msg.set_content("Un backup vient d'etre effectue")
    msg['Subject'] = 'Email de Backup'
    msg['From'] = 'example@example.com'
    msg['To'] = 'example@example.com'
    context = ssl.create_default_context()
    with smtplib.SMTP('smtp.gmail.com', port=587) as smtp:
        smtp.starttls(context=context)
        smtp.login(msg['From'], 'password')
        smtp.send_message(msg)