-
Notifications
You must be signed in to change notification settings - Fork 0
40 lines (35 loc) · 1.62 KB
/
backup-ftp-database.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
name: Backup MariaDB Database FTP
on:
schedule:
- cron: '0 */12 * * *' # Run every 12 hours, backup at 00:00 and 12:00 each day
workflow_dispatch:
jobs:
backup_database:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install MariaDB Client and Gzip
run: sudo apt-get update && sudo apt-get install -y gzip mariadb-client
- name: MySQLDump - Connect Database and Backup MariaDB Database FTP
run: |
mkdir backup_databases && cd backup_databases && mkdir ${{ secrets.DATABASE_DB_NAME }} && cd ${{ secrets.DATABASE_DB_NAME }}
FILENAME="database_${{ secrets.DATABASE_DB_NAME }}_backup-$(date +%d-%m-%Y-%H-%M-%S).sql.gz"
mysqldump \
--host='${{ secrets.DATABASE_HOST }}' \
--user='${{ secrets.DATABASE_USERNAME }}' \
--password='${{ secrets.DATABASE_PASSWORD }}' \
--databases ${{ secrets.DATABASE_DB_NAME }} | gzip > $FILENAME
- name: Set the current date and time
run: echo "CURRENT_DATETIME=$(date +%d-%m-%Y-%H-%M-%S)" >> $GITHUB_ENV
- name: Deploy backup .sql to FTP
uses: SamKirkland/FTP-Deploy-Action@v4.3.4
with:
server: ${{ secrets.SERVER_FTP_HOST }}
username: ${{ secrets.SERVER_FTP_USERNAME }}
password: ${{ secrets.SERVER_FTP_PASSWORD }}
port: ${{ secrets.SERVER_FTP_PORT }}
protocol: ftp
local-dir: ./backup_databases/
server-dir: backup_databases/
state-name: .ftp-deploy-sync-state-${{ secrets.DATABASE_DB_NAME }}-${{ env.CURRENT_DATETIME }}.json