Skip to content

Instantly share code, notes, and snippets.

@mikedamoiseau
mikedamoiseau / backup-db.sh
Last active November 27, 2022 07:23
Script to backup a MySQL database and send the dump by email and/or scp
#!/bin/bash
# ----------------------------------
# DEFINED - Global variables
# ----------------------------------
# defined temporary folder
DBBACKUP="dbbackup"
# database configure
@samuelkordik
samuelkordik / backup.php
Created September 7, 2013 21:26
Simple PHP script to backup MySQL database and email results to me. Adapted from (here)[http://davidwalsh.name/backup-mysql-database-php] with improvements made including using MySQLi, gzipping the backup file (significantly reduces time to email), adding a timing function, and generally making more functional. Note two functions here left fairl…
<?php
/**
* Handles backing up database automatically and emailing it to me.
*/
date_default_timezone_set('America/Chicago'); // necessary in some server environments before using any Date/Time functions.
$timestart = microtime(true);
config(); // sets up constants and configurations for database credentials, error handling, etc. including using local environment specific options.
$filename = backup_tables(DB_HOST, DB_USER, DB_PASS, DB_NAME); // backs up data.