From df48c01c1b000d597852a8ae752952cf1eb49f1c Mon Sep 17 00:00:00 2001 From: Yigit Colakoglu Date: Fri, 16 Apr 2021 23:27:49 +0300 Subject: [PATCH] Backup script improved, zsh startup time boost --- .config/zsh/.zshrc | 9 +++++++-- .local/bin/backup | 17 +++++++++-------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/.config/zsh/.zshrc b/.config/zsh/.zshrc index 3ba0d3ec..16f8db77 100644 --- a/.config/zsh/.zshrc +++ b/.config/zsh/.zshrc @@ -1,3 +1,4 @@ +#zmodload zsh/zprof eval "$(direnv hook zsh)" >> $XDG_RUNTIME_DIR/direnv paleofetch if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then @@ -11,9 +12,12 @@ source <(antibody init) #Autocompletion autoload -Uz compinit -compinit +if [[ -n $XDG_CACHE_HOME/zsh/zcompdump-$ZSH_VERSION ]]; then + compinit -d $XDG_CACHE_HOME/zsh/zcompdump-$ZSH_VERSION +else + compinit -C -d $XDG_CACHE_HOME/zsh/zcompdump-$ZSH_VERSION +fi; -compinit -d $XDG_CACHE_HOME/zsh/zcompdump-$ZSH_VERSION [[ ! -d "$XDG_DATA_HOME"/zsh/history ]] || source "$XDG_DATA_HOME"/zsh/history HISTSIZE=100000 @@ -134,3 +138,4 @@ if (( ${+terminfo[smkx]} && ${+terminfo[rmkx]} )); then add-zle-hook-widget -Uz zle-line-init zle_application_mode_start add-zle-hook-widget -Uz zle-line-finish zle_application_mode_stop fi +#zprof diff --git a/.local/bin/backup b/.local/bin/backup index fb6e85a1..9662f126 100755 --- a/.local/bin/backup +++ b/.local/bin/backup @@ -9,12 +9,13 @@ readonly SSH_HOST=192.168.1.8 readonly SSH_USER=yigit readonly SSH_KEY="/home/yigit/.ssh/id_skeleton" readonly RSYNC_PROFILE="$SSH_USER@$SSH_HOST:~/snapshots" + +alias ssh_cmd="ssh -i \"$SSH_KEY\" $SSH_USER@$SSH_HOST" + DEVICE=tatooine OPT="-aPh" -LINK="--link-dest=$RSYNC_PROFILE/$DEVICE/last/" SNAP="$RSYNC_PROFILE/$DEVICE/" -LAST="$RSYNC_PROFILE/$DEVICE/last" -date=$(date "+%Y-%b-%d:_%T") +date=$(date "+%I:%M-%d.%m.%Y") # You should enter absolute paths DIRS="/home/yigit /etc @@ -27,15 +28,15 @@ timeout 3 ssh -i "$SSH_KEY" $SSH_USER@$SSH_HOST id < /dev/null > /dev/null 2> /d # Run rsync to create snapshot while IFS= read -r DIR do - DEST=$(echo "$DIR" | sed "s/\/[^\/]*$//g") - ssh -i "$SSH_KEY" $SSH_USER@$SSH_HOST mkdir -p "~/snapshots/$DEVICE/$date$DEST" < /dev/null - rsync "$@" -e "ssh -i $SSH_KEY" $OPT "$LINK" "$DIR" "${SNAP}$date$DEST" + LINK="--link-dest=/home/$SSH_USER/snapshots/tatooine/last$DIR/" + ssh -i "$SSH_KEY" $SSH_USER@$SSH_HOST mkdir -p "~/snapshots/$DEVICE/$date$DIR" < /dev/null + rsync --exclude '.cache' "$@" -e "ssh -i $SSH_KEY" $OPT "$LINK" "$DIR/" "${SNAP}$date$DIR/" done << EOF $DIRS EOF # Remove symlink to previous snapshot -rm -f "$LAST" +ssh_cmd rm -f "~/snapshots/$DEVICE/last" < /dev/null # Create new symlink to latest snapshot for the next backup to hardlink -ln -s "${SNAP}$date" "$LAST" +ssh -i "$SSH_KEY" $SSH_USER@$SSH_HOST ln -s "~/snapshots/$DEVICE/$date" "~/snapshots/$DEVICE/last" < /dev/null