Skip to content

Instantly share code, notes, and snippets.

@daviddeutsch
Last active June 30, 2022 10:33
Show Gist options
  • Save daviddeutsch/8f8eb28056ec65f0c439e3740d7694cc to your computer and use it in GitHub Desktop.
Save daviddeutsch/8f8eb28056ec65f0c439e3740d7694cc to your computer and use it in GitHub Desktop.
My backup / new system setup Makefile
SHELL := /bin/bash
.PHONY: backup-daily backup-weekly
uname = $(shell whoami)
# Two storage mediums I keep on daily/weekly rotation
# just put in your own device UUID
dailyMediaUuid = UUID1
weeklyMediaUuid = UUID2
backupExcludeList = --exclude='/home/$(uname)/.gvfs' \
--exclude='/home/$(uname)/.local/share/Trash' \
--exclude='/var/run/*' \
--exclude='/var/lock/*' \
--exclude='/lib/modules/*/volatile/.mounted' \
--exclude='/var/cache/apt/archives/*' \
--exclude='/home/$(uname)/.mozilla/firefox/*/Cache' \
--exclude='/home/$(uname)/.mozilla/firefox/*/cache2' \
--exclude='/home/$(uname)/.cache/chromium'
--exclude='/home/$(uname)/.thumbnails' \
--exclude='/home/$(uname)/.cache' \
--exclude='/tmp'
dailyBackupPath = /media/$(uname)/$(dailyMediaUuid)
weeklyBackupPath = /media/$(uname)/$(weeklyMediaUuid)
atfs = /tmp/new-machine-setup
backup-daily:
time sudo rsync -avxHAXS --delete --numeric-ids --info=progress2 / $(dailyBackupPath)/ $(backupExcludeList)
backup-weekly:
time sudo rsync -avxHAXS --delete --numeric-ids --info=progress2 / $(weeklyBackupPath)/ $(backupExcludeList)
ubuntuCodename = $(shell lsb_release -c -s | tr -d '\n')
restore-daily-backup: \
~/workspace/ \
~/Documents/ \
~/Videos/ \
~/Dropbox/ \
~/tmp/ \
~/Pictures/ \
~/Downloads/ \
~/Dropbox/ \
~/.dropbox/ \
~/.thunderbird/ \
~/.mozilla/firefox/ \
~/.config/JetBrains/ \
~/.local/share/JetBrains/ \
~/.local/share/TelegramDesktop/ \
~/.local/share/vlc/ \
~/.config/inkscape/ \
~/.config/obs-studio/ \
~/.config/obs-studio-new/ \
~/.config/vlc/ \
~/.config/Signal/ \
~/.bash_history \
~/.bashrc \
~/.gitconfig \
~/.wine/ \
~/.ssh/ \
~/.fonts/ \
~/%/:
time rsync -avxHAXS --info=progress2 $(dailyBackupPath)/home/$(uname)/$*/* ~/$*/
~/%:
time rsync -avxHAXS --info=progress2 $(dailyBackupPath)/home/$(uname)/$* ~/$*
.PHONY: server-stuff-setup
server-stuff-setup: $(atfs)/enable-nginx
$(atfs)/enable-nginx: $(atfs)/disable-apache2
sudo systemctl enable nginx
sudo service nginx restart
touch $@
$(atfs)/disable-apache2:
sudo service apache2 stop
sudo update-rc.d apache2 disable
touch $@
.PHONY: setup-new-machine
setup-new-machine: \
$(atfs)/assemble-raids \
$(atfs)/copy-etc-hosts \
$(atfs)/copy-nginx-enabled \
install-software
$(atfs)/assemble-raids: \
$(atfs)/install-mdadm \
$(atfs)/install-parted
sudo mdadm --assemble --scan
touch $@
$(atfs)/copy-nginx-enabled:
sudo rsync -avxHAXS --info=progress2 $(dailyBackupPath)/etc/nginx/sites-enabled/ /etc/nginx/sites-enabled/
touch $@
$(atfs)/copy-etc-hosts:
sudo cp $(dailyBackupPath)/etc/hosts /etc/hosts
touch $@
.PHONY: install-software
install-software: \
$(atfs)/install-inkscape \
$(atfs)/install-thunderbird \
$(atfs)/install-dropbox \
$(atfs)/install-signal \
$(atfs)/install-git \
$(atfs)/install-gimp \
$(atfs)/install-fzf \
$(atfs)/install-ffmpeg \
$(atfs)/install-yubikey-manager \
$(atfs)/install-keepassxc \
$(atfs)/install-phpstorm \
$(atfs)/install-telegram-desktop \
$(atfs)/install-php-xdebug \
$(atfs)/install-git-gui \
$(atfs)/install-rust \
$(atfs)/install-simplescreenrecorder \
$(atfs)/install-yt-dlp
$(atfs)/:
mkdir $@
$(atfs)/install-%: | $(atfs)
sudo apt-get install -y $*
touch $@
$(atfs)/install-inkscape: | $(atfs)/
sudo add-apt-repository ppa:inkscape.dev/trunk
sudo apt-get update
sudo apt-get install inkscape-trunk
touch $@
$(atfs)/install-yt-dlp: $(atfs)/install-python | $(atfs)/
sudo curl -L https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -o /usr/local/bin/yt-dlp
sudo chmod a+rx /usr/local/bin/yt-dlp
touch $@
$(atfs)/install-rust: | $(atfs)/
curl https://sh.rustup.rs -sSf | sh
touch $@
$(atfs)/install-signal: | $(atfs)
wget -O- https://updates.signal.org/desktop/apt/keys.asc | gpg --dearmor > signal-desktop-keyring.gpg
cat signal-desktop-keyring.gpg | sudo tee -a /usr/share/keyrings/signal-desktop-keyring.gpg > /dev/null
echo 'deb [arch=amd64 signed-by=/usr/share/keyrings/signal-desktop-keyring.gpg] https://updates.signal.org/desktop/apt $(ubuntuCodename) main' |\
sudo tee -a /etc/apt/sources.list.d/signal-$(ubuntuCodename).list
sudo apt update && sudo apt install signal-desktop
touch $@
$(atfs)/install-keepassxc: $(atfs)/install-yubikey-manager | $(atfs)
sudo add-apt-repository ppa:phoerious/keepassxc
sudo apt-get update
sudo apt-get install -y keepassxc
touch $@
$(atfs)/install-yubikey-manager: | $(atfs)
sudo add-apt-repository ppa:yubico/stable && sudo apt-get update
sudo apt-get install -y yubikey-manager yubikey-personalization-gui
touch $@
$(atfs)/install-phpstorm: $(atfs)/PhpStorm-2021.3.1.tar.gz
tar -xvzf $< -C /home/$(uname)
touch $@
$(atfs)/PhpStorm-2021.3.1.tar.gz: $(atfs)/install-curl | $(atfs)
curl -L https://download.jetbrains.com/webide/PhpStorm-2021.3.1.tar.gz > $@
$(atfs)/install-dropbox: $(atfs)/dropbox_2020.03.04_amd64.deb $(atfs)/install-libpango1.0-0 | $(atfs)
sudo dpkg -i $(atfs)/dropbox_2020.03.04_amd64.deb
touch $@
$(atfs)/dropbox_2020.03.04_amd64.deb: $(atfs)/install-curl | $(atfs)
curl -L https://www.dropbox.com/download?dl=packages/ubuntu/dropbox_2020.03.04_amd64.deb > $@
$(atfs)/install-wine: $(atfs)/winehq.key
sudo -H gpg -o /etc/apt/trusted.gpg.d/winehq.key.gpg --dearmor $(atfs)/winehq.key
sudo apt-get update
sudo add-apt-repository 'deb https://dl.winehq.org/wine-builds/ubuntu/ $(ubuntuCodename) main'
sudo apt install --install-recommends winehq-stable
$(atfs)/winehq.key:
wget -nc https://dl.winehq.org/wine-builds/winehq.key
# Still missing: Seems like we need /var/log/nginx/* directories for each local domain we copy over
# Also missing: Add nginx to own usergroup so it can access directories
# Also https://nystudio107.com/blog/installing-mozjpeg-on-ubuntu-16-04-forge
# BUT! Don't do sudo ln -s /opt/mozjpeg/bin/jpegtran /usr/bin/mozjpeg - it should be /opt/mozjpeg/bin/cjpeg
# https://github.com/jaakkopasanen/AutoEq for Headphones
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment