Skip to content

Instantly share code, notes, and snippets.

@yayMark
Created June 12, 2021 00:58
Show Gist options
  • Save yayMark/f58af37cc171790075eee3cdcad9b3e3 to your computer and use it in GitHub Desktop.
Save yayMark/f58af37cc171790075eee3cdcad9b3e3 to your computer and use it in GitHub Desktop.
Shell: backup web directory and database
#!/bin/bash
_project="project"
_env="local"
_root="/mnt/c/work/hmr/backups"
_webdir="web"
_webext=".tar.gz"
if [ -n "$1" ] && [ "$1" != " " ]; then
_suffix="-$1"
else
_suffix=""
fi
_currentdir=$(pwd -P)
_now=$(date +"%Y%m%dT%H%M")
_name="$_project-$_env-$_now$_suffix"
_dbfile="$_name.sql"
_webfile="$_name$_webext"
##Tests start
#echo "First arg: $1"
#echo "Database: $_project"
#echo "Database file: $_dbfile"
#echo "Web files: $_webfile"
#exit
##Tests end
cd "$_root" || exit
echo "Starting database backup to $_dbfile..."
sudo mysqldump "$_project" > "$_root/$_dbfile"
cd .. || exit
echo "Starting web files backup to $_webfile..."
tar czf - "$_webdir" | pv > "$_root/$_webfile"
cd "$_currentdir" || exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment