Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/zsh
- # zsh-sysbackup.zsh
- # Ashton Hellwig @ashellwig
- # Purpose: Performs a full system backup using Rsync
- # --- Pre-Backup ---
- function pre_run_func() {
- local build_dir="~/tmp/BUILDS"
- mkdir -p "${build_dir}"
- cat << END > "${build_dir}/rsync-exclude.txt"
- /home/ahellwig/tmp/***
- /home/ahellwig/.cache/***
- /home/ahellwig/.vscode/***
- /home/ahellwig/.cargo/***
- /home/ahellwig/.rustup/***
- /home/ahellwig/.cargo/***
- /home/ahellwig/.g*/***
- /dev/*
- /proc/*
- /sys/*
- /tmp/*
- /run/*
- /mnt/*
- /media/*
- /lost+found
- /swapfile
- /srv/*
- /var/log/*
- END
- cd "${build_dir}"
- return
- }
- # --- Backup Function ---
- function run_func() {
- # For production, replace '--dry-run' with '--info=flist2,name,progress'
- local build_dir="~/tmp/BUILDS"
- sudo rsync '-aAxXhHv' '--partial' '--delete' '--dry-run' '--exclude-from="${build_dir}/rsync-exclude.txt"' '/' '/mnt/backup'
- return
- }
- # --- Clean Function ---
- function clean_func() {
- local build_dir="~/tmp/BUILDS"
- if [[ "$(pwd)" = "${build_dir}"]]; then
- cd ~
- fi
- rm '-rf' "${build_dir}"
- return
- }
- # --- Call to Functions ---
- function main_func() {
- print -f "\033[3;33m\nCreating Necessary Directories...\033[0m\n"
- pre_run_func
- print -f "\n\033[3;4;32mBeginning Backup\033[0m\n"
- run_func
- print -f "\n\033[3;33m \033[0m\n"
- clean_func
- print -f "\n\033[3;33mUnsetting functions and variables...\033[0m\n"
- if [[ -v build_dir ]]; then
- unset build_dir
- fi
- unfunction pre_run_func &
- unfunction run_func &
- unfunction clean_func
- print -f "\n\033[1;32mDone!\033[0m\n"
- return 0
- }
- # --- Script ---
- main_func
- # Final Cleanup
- unfunction main_func
- return 0
- # vim: set et ts=2 sw=2 ft=zsh:
Add Comment
Please, Sign In to add comment