Created
May 9, 2020 22:05
-
-
Save e1en0r/7703452ae5327a669da70d62656cfc5a to your computer and use it in GitHub Desktop.
Simple backup script
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 | |
do_backup() { | |
source_dir="$(cd "$(dirname "$1")"; pwd)" | |
source_file="$(basename "$1")" | |
source="$source_dir/$source_file" | |
if [ "$2" != "" ]; then | |
dest_root="$2" | |
else | |
dest_root="$HOME/Backups/mirror" | |
fi | |
dest_path="$dest_root/$source_dir" | |
mkdir -p "$dest_path" | |
sudo cp -R $source $dest_path | |
sudo chown -R ${USER:=$(/usr/bin/id -run)}:$USER $dest_path | |
echo "Backed up $1 from $source to $dest_path" | |
} | |
if [ "$1" != "" ]; then | |
do_backup $1 $2 | |
else | |
echo "Missing file name" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment