Created
May 13, 2024 20:38
-
-
Save PassiHD2004/09e58f25a1db5d8d055c5a88fe6246fd to your computer and use it in GitHub Desktop.
Configs backup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This script will backup all mysql databases into | |
# compressed file named after date, ie: /var/backup/mysql/2024-05-09_07:00.zip | |
# Setup variables used later | |
# Create date suffix with "F"ull date format and add hour:time | |
suffix=$(date +%F_%H:%M) | |
# Create temporary directory with "-d" option | |
tmp="<tmpdir>" | |
# Set output dir here. /var/backups/ is used by system, | |
# so intentionally used /var/backup/ for user backups. | |
outDir="<outputdir>" | |
# Create output file name | |
out="$outDir/$suffix.zip" | |
# Set remote backup target | |
target="<remotetarget>" | |
# Actual script | |
if [ ! -d "$tmp" ];then | |
# Create directory with parent ("-p" option) directories | |
sudo mkdir -p "$tmp" | |
fi | |
# Check if output directory exists | |
if [ ! -d "$outDir" ];then | |
# Create directory with parent ("-p" option) directories | |
sudo mkdir -p "$outDir" | |
fi | |
ls "$tmp" | |
sudo cp -r /etc "$tmp" | |
sudo cp -r /opt "$tmp" | |
# Go to tmp dir | |
cd $tmp | |
# Compress all dumps with bz2, discard any output to /dev/null | |
sudo zip -r "$out" * > "/dev/null" | |
# Backup to remote target | |
scp "$out" "$target" | |
# Cleanup | |
sudo rm -rf "$tmp/" | |
cd "$outDir/" | |
find . -maxdepth 1 -mtime 7 -type f -name "*.zip" -exec rm -f {} ';' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment