{"id":21384461,"url":"https://github.com/daljitdokal/ansible-mysql-backup","last_synced_at":"2025-04-15T19:35:54.097Z","repository":{"id":167743635,"uuid":"374205205","full_name":"daljitdokal/ansible-mysql-backup","owner":"daljitdokal","description":"Ansible playbook to create MySQL database backup from remote server.","archived":false,"fork":false,"pushed_at":"2023-01-24T04:38:19.000Z","size":54,"stargazers_count":8,"open_issues_count":0,"forks_count":5,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-29T00:11:33.038Z","etag":null,"topics":["ansible-playbook","automation","backup","mysql","ssh"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/daljitdokal.png","metadata":{"files":{"readme":"README.org","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-06-05T20:20:33.000Z","updated_at":"2025-01-15T07:22:17.000Z","dependencies_parsed_at":"2023-09-14T08:47:04.992Z","dependency_job_id":null,"html_url":"https://github.com/daljitdokal/ansible-mysql-backup","commit_stats":null,"previous_names":["daljitdokal/ansible-mysql-backup"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daljitdokal%2Fansible-mysql-backup","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daljitdokal%2Fansible-mysql-backup/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daljitdokal%2Fansible-mysql-backup/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daljitdokal%2Fansible-mysql-backup/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/daljitdokal","download_url":"https://codeload.github.com/daljitdokal/ansible-mysql-backup/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249139402,"owners_count":21219064,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ansible-playbook","automation","backup","mysql","ssh"],"created_at":"2024-11-22T11:41:00.448Z","updated_at":"2025-04-15T19:35:54.078Z","avatar_url":"https://github.com/daljitdokal.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Backup MySql databases from remote server\n\n** Description\nI have wordpress websites running on VPS server and I need a solution to backup these databases regulerly.\nWe will create an [[https://www.ansible.com][ansible]] playbook (step by stepp process) to automate the solution.\n\n** Prerequisites\n - [[https://docs.oracle.com/en/cloud/cloud-at-customer/occ-get-started/generate-ssh-key-pair.html][ssh key]] (make sure public key has been uploaded to remote server)\n - [[https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html][ansible]]\n - A running instance of MySQL\n\n** Step 1: Create inventory file\nCreate new file as 'server.inventory.ini'\n#+BEGIN_SRC\ntouch server.inventory.ini\n#+END_SRC\n\nAdd the following details\n#+BEGIN_SRC\n[Server-VPS]\n# server address here\n\n[Server-VPS:vars]\nansible_connection=ssh\nansible_user= # remote server username\n#+END_SRC\n\n** Step 2: Create vault file\n*** Step 2.1: Create file with secrets\nCreate new file as 'database_vault.yaml'\n#+BEGIN_SRC\ntouch database_vault.yaml\n#+END_SRC\n\nAdd the following details\n#+BEGIN_SRC\n db_name: # database name here\n db_user_name: # database username here\n db_user_password: # database user password here\n#+END_SRC\n\n*** Step 2.2: Encrypt secret file\nPlease run the following command to [[https://www.digitalocean.com/community/tutorials/how-to-use-vault-to-protect-sensitive-ansible-data-on-ubuntu-16-04#:~:text=To%20create%20a%20new%20file,encrypted%20YAML%20file%20called%20vault.][encrypt]] newly created secrets file.\n#+BEGIN_SRC\n ansible-vault encrypt database_vault.yaml\n#+END_SRC\n\n#+BEGIN_SRC\n # output\n New Vault password: \n Confirm New Vault password:\n Encryption successful\n#+END_SRC\n\n*** Step 3: Create playbook\nCreate new file as 'database_backup_playbook.yaml'\n#+BEGIN_SRC\ntouch database_backup_playbook.yaml\n#+END_SRC\n\nAdd the following details\n#+BEGIN_SRC yaml :tangle database_backup_playbook.yaml\n  ---\n  - hosts: Server-VPS\n    gather_facts: true\n    vars_files:\n      - database_vault.yaml\n    tasks:\n      - name: Create variables\n        set_fact:\n          db_file_name: \"{{ db_name }}_{{ ansible_date_time.date | replace('-','') }}.sql\"\n      \n      - name: Confirm hostname\n        debug:\n          msg: Logged into the server.\n\n      - name: Download Database to server\n        shell: |\n          mysqldump -u {{ db_user_name}} -p\"{{ db_user_password }}\" {{ db_name }} --quick --lock-tables=false \u003e \"{{ db_file_name }}\" --no-tablespaces\n        no_log: true\n\n      - name: Wait until the database backup completed on server\n        wait_for:\n          path: \"{{ db_file_name }}\"\n          state: present\n          msg: \"Timeout to find file {{ db_file_name }}\"\n\n      - name: Downloading backup to local computer\n        ansible.builtin.fetch:\n          src: \"{{ db_file_name }}\"\n          dest: \"{{ db_file_name }}\"\n          flat: yes\n\n      - name: Download completed\n        debug:\n          msg: Database have been downloaded successfully.\n#+END_SRC\n\n*** Step 4: Time to playbook to run manually in command-line:\n\n*** Step 4.1 - Run ssh-agent\nIf you have the passpharace added to ssh key then it will be easier to run it manually.\n#+begin_src\n  eval $(ssh-agent)\n  ssh-add ./path/to/ssh/key\n#+end_src\n\n*** Step 4.2 - Execute playbook\nPlease execute following command to run the playbopk and start the process.\n#+BEGIN_SRC bash\n  ansible-playbook -i server.inventory.ini database_backup_playbook.yaml --ask-vault-password\n#+END_SRC\n\n*** Step 4.3: Enter vault password.\nPlease enter the vault password so that ansible can decyrpt the `database_vault.yaml` variables to use in the playbook.\n\n* Install `AWX` on `k3s`cluster\n\n- Please use the following [[https://github.com/daljitdokal/install-awx-with-k3s-cluster][link]] to view step by step docmentation to install `awx` on `k3s`.\n- Please use the following [[https://github.com/daljitdokal/raspberry-pi-ubuntu-server-k3s-awx-ansible-automated-setup][link]] to view Step by step process to build ubuntu-server on raspberry-pi with k3s, kubernetes-dashboard, awx and awx job template with ansible paybooks (mysql datbase backup from remote server).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaljitdokal%2Fansible-mysql-backup","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdaljitdokal%2Fansible-mysql-backup","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaljitdokal%2Fansible-mysql-backup/lists"}