Copia de seguridad MySQL

Script para crear copias de seguridad en MySQL

#!/bin/sh
now="$(date +'%d_%m_%Y_%H_%M_%S')"
filename="db_backup_$now".gz
backupfolder="/var/www/vhosts/example.com/httpdocs/backups"
fullpathbackupfile="$backupfolder/$filename"
logfile="$backupfolder/"backup_log_"$(date +'%Y_%m')".txt
echo "mysqldump started at $(date +'%d-%m-%Y %H:%M:%S')" >> "$logfile"
mysqldump --user=mydbuser --password=mypass --default-character-set=utf8 mydatabase | gzip > "$fullpathbackupfile"
echo "mysqldump finished at $(date +'%d-%m-%Y %H:%M:%S')" >> "$logfile"
chown myuser "$fullpathbackupfile"
chown myuser "$logfile"
echo "file permission changed" >> "$logfile"
find "$backupfolder" -name db_backup_* -mtime +8 -exec rm {} \;
echo "old files deleted" >> "$logfile"
echo "operation finished at $(date +'%d-%m-%Y %H:%M:%S')" >> "$logfile"
echo "*****************" >> "$logfile"
exit 0
Anuncios

Select TOP equivalencias en otros lenguajes

SQL Server / MS Access

SELECT TOP number|percent column_name(s)
FROM table_name;

SQL SELECT TOP equivalencia en MySQL and Oracle

MySQL

SELECT column_name(s)
FROM table_name
LIMIT number;

Ejemplo

SELECT *
FROM Persons
LIMIT 5;

Oracle

SELECT column_name(s)
FROM table_name
WHERE ROWNUM <= number;

Ejemplo

SELECT *
FROM Persons
WHERE ROWNUM <=5;