Database backups are a vital disaster-recovery requirement for production systems. In containerized or multi-tier infrastructure environments, database instances often run on dedicated application nodes or database servers, while long-term backups must be archived on centralized storage nodes.
This challenge configures an automated, periodic database backup pipeline using Jenkins:
*/10 * * * *).mysqldump over an SSH connection to stream a database dump of kodekloud_db01 directly from App Server 1 (stapp01).db_$(date +%F).sql e.g. db_2026-07-28.sql).scp to Storage Server (ststor01) under /home/natasha/db_backups/.graph TD
subgraph CronScheduler ["Jenkins Controller (Cron)"]
Trigger["Build Periodically Trigger: */10 * * * *"]
Job["Freestyle Job: database-backup"]
Workspace["Jenkins Staging Workspace<br/>/var/lib/jenkins/workspace/database-backup"]
end
subgraph AppServer ["App Server 1 (stapp01)"]
MySQL["MySQL Database Server<br/>DB: kodekloud_db01<br/>User: kodekloud_roy"]
DumpCmd["mysqldump Stream"]
end
subgraph StorageServer ["Storage Server (ststor01)"]
TargetDir["Storage Location<br/>/home/natasha/db_backups/"]
SqlDumpFile["db_YYYY-MM-DD.sql"]
end
Trigger -->|1. Triggers Job Every 10 Mins| Job
Job -->|2. SSH Stream mysqldump| DumpCmd
DumpCmd -->|3. Extract DB Tables| MySQL
DumpCmd -->|4. Redirect Output Stream to File| Workspace
Workspace -->|5. SCP transfer file| TargetDir
TargetDir -->|6. Save Backup| SqlDumpFile
Workspace -->|7. rm -f local file| Workspace
mysqldump over SSHmysqldump creates a logical backup of a MySQL/MariaDB database by emitting SQL statements required to rebuild tables and insert data:
-u kodekloud_roy -pasdfgdsd directly in the command avoids interactive password prompts during automated batch runs.mysqldump inside an ssh invocation streams the SQL stdout output over the SSH tunnel into a local file on the Jenkins workspace:
ssh -o StrictHostKeyChecking=no stapp01 "mysqldump -u kodekloud_roy -pasdfgdsd kodekloud_db01" > "db_$(date +%F).sql"
date +%F)The Linux command date +%F outputs the current date in standard ISO-8601 format (YYYY-MM-DD). Constructing the filename as db_$(date +%F).sql guarantees predictable, chronological naming for daily backup archives (e.g., db_2026-07-28.sql).
8080admin / Adm!n321stapp01tonykodekloud_db01kodekloud_royasdfgdsdststor01natasha/home/natasha/db_backups/database-backup*/10 * * * *)#!/bin/bash
# Define the backup filename using the current date
DUMP_FILE="db_$(date +%F).sql"
# Stream the database dump from App Server (stapp01) to Jenkins workspace
ssh -o StrictHostKeyChecking=no stapp01 "mysqldump -u kodekloud_roy -pasdfgdsd kodekloud_db01" > "${DUMP_FILE}"
# Securely copy the dump from Jenkins workspace to Storage Server (ststor01)
scp -o StrictHostKeyChecking=no "${DUMP_FILE}" ststor01:/home/natasha/db_backups/
# Clean up the local workspace staging file
rm -f "${DUMP_FILE}"
Before running the Jenkins build, verify passwordless SSH keys and directory structure across the servers:
ststor01:
ssh natasha@ststor01 "mkdir -p /home/natasha/db_backups/"
stapp01 and ststor01:
ssh -o StrictHostKeyChecking=no stapp01 "hostname"
ssh -o StrictHostKeyChecking=no ststor01 "hostname"
adminAdm!n321
Upon signing in, verify access to the Jenkins welcome landing page:

database-backup Freestyle Projectdatabase-backup as the item name.
*/10 * * * *

#!/bin/bash
# Define the backup filename using the current date
DUMP_FILE="db_$(date +%F).sql"
# Stream the database dump from App Server (stapp01) to Jenkins workspace
ssh -o StrictHostKeyChecking=no stapp01 "mysqldump -u kodekloud_roy -pasdfgdsd kodekloud_db01" > "${DUMP_FILE}"
# Securely copy the dump from Jenkins workspace to Storage Server (ststor01)
scp -o StrictHostKeyChecking=no "${DUMP_FILE}" ststor01:/home/natasha/db_backups/
# Clean up the local workspace staging file
rm -f "${DUMP_FILE}"

Finished: SUCCESS:
ststor01):
ssh natasha@ststor01
cd /home/natasha/db_backups/
ls -la
db_2026-07-28.sql):
The Jenkins database backup pipeline is now fully operational and configured to run automatically every 10 minutes!