backup.sh 550 B

12345678910
  1. #!/bin/bash
  2. suffix=$(date -d 'today' +%Y-%m-%dT%H:%M)
  3. tmpdir=$(mktemp -d)
  4. sql_file="mariadb-$suffix.sql"
  5. echo "Dumping MySQL database from host $SQL_HOSTNAME into file $sql_file"
  6. mariadb-dump --host="$SQL_HOSTNAME" --user="$SQL_USERNAME" --password="$SQL_PASSWORD" -x --all-databases > "$tmpdir"/"$sql_file" || exit 1
  7. echo "Sending backup to ${BCK_USERNAME}@${BCK_HOSTNAME}"
  8. 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