Home
DevCentral
Search
Configure Global Search
Log In
Transactions
P367
Change Details
Change Details
Old
New
Diff
#!/bin/sh # ------------------------------------------------------------- # Backup MariaDB or MySQL databases # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Project: Nasqueron # License: BSD-2-Clause # ------------------------------------------------------------- set -e BACKUP_DIR=/var/backups/db # ------------------------------------------------------------- # Ensure user is root # # Note: POSIX shells don't always define $UID or $EUID. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - if [ "${EUID:-$(id -u)}" -ne 0 ]; then echo "This command must be run as root." >&2 exit 1 fi # ------------------------------------------------------------- # Collect information # # :: Databases to dump # :: Timestamp # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - DATABASES=$(mysql -Ns -e "show databases" | grep -v -E 'information_schema|performance_schema|mysql-innodb-') SUBDIR=$(hostname -s)-$(date +"%s") mkdir "$BACKUP_DIR/$SUBDIR" for database in $DATABASES; do mysqldump $database | gzip > "$BACKUP_DIR/$SUBDIR/$database.sql.gz" done
#!/bin/sh # ------------------------------------------------------------- # Backup MariaDB or MySQL databases # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Project: Nasqueron # License: BSD-2-Clause # ------------------------------------------------------------- set -e BACKUP_DIR=/var/backups/db # ------------------------------------------------------------- # Ensure user is root # # Note: POSIX shells don't always define $UID or $EUID. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - if [ "${EUID:-$(id -u)}" -ne 0 ]; then echo "This command must be run as root." >&2 exit 1 fi # ------------------------------------------------------------- # Collect information # # :: Databases to dump # :: Timestamp # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - DATABASES=$(mysql -Ns -e "show databases" | grep -v -E 'information_schema|performance_schema|mysql-innodb-') SUBDIR=$(hostname -s)-$(date +"%s") # ------------------------------------------------------------- # Backup # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - mkdir "$BACKUP_DIR/$SUBDIR" for database in $DATABASES; do mysqldump $database | gzip > "$BACKUP_DIR/$SUBDIR/$database.sql.gz" done
#!/bin/sh # ------------------------------------------------------------- # Backup MariaDB or MySQL databases # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Project: Nasqueron # License: BSD-2-Clause # ------------------------------------------------------------- set -e BACKUP_DIR=/var/backups/db # ------------------------------------------------------------- # Ensure user is root # # Note: POSIX shells don't always define $UID or $EUID. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - if [ "${EUID:-$(id -u)}" -ne 0 ]; then echo "This command must be run as root." >&2 exit 1 fi # ------------------------------------------------------------- # Collect information # # :: Databases to dump # :: Timestamp # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - DATABASES=$(mysql -Ns -e "show databases" | grep -v -E 'information_schema|performance_schema|mysql-innodb-') SUBDIR=$(hostname -s)-$(date +"%s")
# ------------------------------------------------------------- # Backup # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
mkdir "$BACKUP_DIR/$SUBDIR" for database in $DATABASES; do mysqldump $database | gzip > "$BACKUP_DIR/$SUBDIR/$database.sql.gz" done
Continue