Created
November 23, 2020 17:52
-
-
Save nithyadurai87/6c3a7035a4ce48372a6d8864e5f65a0b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime | |
from airflow import DAG | |
import os | |
from airflow.operators.python_operator import PythonOperator | |
from airflow.models import Variable | |
usr = Variable.get("mysql_username") | |
pwd = Variable.get("mysql_password") | |
def backup(): | |
backup_cmd = 'mysqldump -u '+usr+' -p'+pwd+' sample > "/home/shrini/backups/"sample_"$(date +"%Y%m%d_%H%M%S").sql"' | |
os.system(backup_cmd) | |
dag = DAG('mysql_backup', description='Mysql backup every hour', schedule_interval='00 * * * *', start_date=datetime(2020, 11, 2), catchup=False) | |
backup_operator = PythonOperator(task_id='backup_task', python_callable=backup, dag=dag) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment