- #!/bin/bash
- suffix=$(date -d 'today' +%Y-%m-%dT%H:%M)
- tmpdir=$(mktemp -d)
- sql_file="mariadb-$suffix.sql"
- echo "Dumping MySQL database from host $SQL_HOSTNAME into file $sql_file"
- mariadb-dump --host="$SQL_HOSTNAME" --user="$SQL_USERNAME" --password="$SQL_PASSWORD" -x --all-databases > "$tmpdir"/"$sql_file" || exit 1
- echo "Sending backup to ${BCK_USERNAME}@${BCK_HOSTNAME}"
- scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i /root/.ssh/id_rsa "$tmpdir"/"$sql_file" "$BCK_USERNAME"@"$BCK_HOSTNAME":"$BCK_FOLDER"/$sql_file || exit 2
|