Skip to content

Instantly share code, notes, and snippets.

@willnode
Created December 1, 2020 07:56
Show Gist options
  • Save willnode/11614dd1e8bfcfd7c4619435e64564a3 to your computer and use it in GitHub Desktop.
Save willnode/11614dd1e8bfcfd7c4619435e64564a3 to your computer and use it in GitHub Desktop.
Bash script to backup MySQL data efficiently
#!/bin/bash
timestamp=`date +%Y%m%d-%H`
tar -cf /root/mysqlb/backup-`echo $timestamp`.tar /var/lib/mysql
gzip -1 /root/mysqlb/backup-`echo $timestamp`.tar
find /root/mysqlb/ -type f -mtime +7 -name '*.gz' -print0 | xargs -r0 rm --
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment