Skip to content

Instantly share code, notes, and snippets.

@dgant
Created June 12, 2023 20:53
Show Gist options
  • Save dgant/495157f5813c72c9fa2f5af84c76112c to your computer and use it in GitHub Desktop.
Save dgant/495157f5813c72c9fa2f5af84c76112c to your computer and use it in GitHub Desktop.
Script to create a datestamped backup of your project
#!/bin/bash
src_dir="/c/MyProject"
base_tgt_dir="/d/MyProjectBackups"
current_date=$(date +"%Y-%m-%d")
tgt_dir="${base_tgt_dir}/${current_date}"
# If the target directory already exists, delete it first
if [ -d "$tgt_dir" ]; then
rm -rf "$tgt_dir"
fi
# Recursively copy the source directory to the target directory with the current date
echo "Backing up from '$src_dir' to '$tgt_dir'"
cp -r "$src_dir" "$tgt_dir"
echo "The directory '$src_dir' has been copied to '$tgt_dir'"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment