Skip to content

Instantly share code, notes, and snippets.

@e1en0r
Created May 9, 2020 22:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save e1en0r/7703452ae5327a669da70d62656cfc5a to your computer and use it in GitHub Desktop.
Save e1en0r/7703452ae5327a669da70d62656cfc5a to your computer and use it in GitHub Desktop.
Simple backup script
#!/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