Created
September 7, 2021 21:57
-
-
Save matu3ba/b2c50d7481e54cc62dfcaa636b256900 to your computer and use it in GitHub Desktop.
simple backup
This file contains hidden or 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 | |
#quick backup script to mess with nvim config | |
## backup all files except those defined in ExcludeArray | |
## NOTE: files in list will not be touched | |
## other (newly created/renamed) files are deleted before restoring | |
#safer defaults https://bertvv.github.io/cheat-sheets/Bash.html | |
set -o errexit # abort on nonzero exitstatus | |
set -o nounset # abort on unbound variable | |
set -o pipefail # don't hide errors within pipes | |
NVIM_PATH="${HOME}/.config/nvim" | |
BACKUP_FOLDER="backup" | |
declare -a ExcludeArray=("${BACKUP_FOLDER}" "backup.sh" "beta_software" "install" "list") | |
if [ -d "${NVIM_PATH}/${BACKUP_FOLDER}" ]; then | |
echo "backup folder exists, please remove folder ${BACKUP_FOLDER}" | |
echo "exiting.." | |
exit 0 | |
fi | |
mkdir ${BACKUP_FOLDER} | |
# get all files at top level, that are not in ExcludeArray | |
for i in "${NVIM_PATH}/*"; do | |
echo ${i} | |
if [[ " ${ExcludeArray[@]} " =~ " ${i} " ]]; then | |
cp -r "${i}" "${NVIM_PATH}/${BACKUP_FOLDER}" | |
fi | |
done | |
echo "generate restore commands.." | |
cat > "${NVIM_PATH}/${BACKUP_FOLDER}/restore.sh" <<EOL | |
#!/bin/bash | |
# execute this script with | |
# bash restore.sh | |
declare -a ExcludeArray=($BACKUP_FOLDER "backup.sh" "beta_software" "install" "list") | |
# clean nvim config | |
for i in "$NVIM_PATH/*"; do | |
if [[ " ${ExcludeArray[@]} " =~ " ${i} " ]]; then | |
echo rm -fr "${i}" | |
fi | |
done | |
for i in "${NVIM_PATH}/${BACKUP_FOLDER}/*"; do | |
if [[ "${i}" -eq "${NVIM_PATH}/${BACKUP_FOLDER}/restore.sh" ]]; then | |
continue | |
fi | |
if [[ " ${ExcludeArray[@]} " =~ " ${i} " ]]; then | |
echo cp -r "${i}" | |
fi | |
done | |
EOL | |
echo "done. have fun configuring nvim!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment