Skip to content

Instantly share code, notes, and snippets.

@fljdin
Last active August 26, 2019 12:36
Show Gist options
  • Save fljdin/4abcca8868dd324bcf60784e148f0884 to your computer and use it in GitHub Desktop.
Save fljdin/4abcca8868dd324bcf60784e148f0884 to your computer and use it in GitHub Desktop.
#!/bin/bash
echo -n "Starting backup... Are you sure ? y/(n) " ; read response
test ${response:-n} != "y" && exit 1
dotfiles=$(dirname $0)/dotfiles.txt
destination=$(dirname $0)/home
# create dotfiles archives or append new files to it
tar -czf $HOME/dotfiles.tar.gz -C $HOME --files-from=$dotfiles
rsync -av $HOME/dotfiles.tar.gz "$destination"
# retrieve all visible directories and dotfiles archives
dir_options="-mindepth 1 -maxdepth 1 -type d"
while IFS= read -r -d '' directory ; do
(
# ignore git subfolders
find $directory -type d -name .git -exec dirname {} \; | sed -e "s;$HOME/;;" -e 's;$;/*;'
# ignore large files
find $directory -type f -size +200M | sed -e "s;$HOME/;;"
) > $HOME/.exclude
test -s $HOME/.exclude && excludefrom="--exclude-from=$HOME/.exclude"
rsync $excludefrom -av "$directory" "$destination"
unset excludefrom
done < <(find $HOME $dir_options -name "[^.]*" -print0)
echo -n "Backup done. Press a key..." ; read
#! /bin/bash
### Restore commands
cd /run/media/$(whoami)/*
tar -xf home/dotfiles.tar.gz -C $HOME
rsync --exclude=dotfiles.tar.gz -av home/ $HOME
chown -R $(whoami): $HOME
### Software install
# sudo pacman -Syu
# sudo pacman -Sy firefox thunderbird keepassxc autorandr libvirt virt-manager
# pamac build dino spotify-dev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment