Skip to content

Commit

Permalink
backup with rsync/ssh
Browse files Browse the repository at this point in the history
  • Loading branch information
pad92 committed May 11, 2023
1 parent aff6b4b commit 2f8e88d
Show file tree
Hide file tree
Showing 13 changed files with 23 additions and 18 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@
.config/nitrogen/bg-saved.cfg
.config/gtk-3.0/bookmarks
.config/gtk-3.0/servers

dist/*/pkglist-*-*.txt
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Configuration used on my [Arch Linux](https://archlinux.org/) with i3 / i3status

![screenshot](https://gitlab.com/pad92/dotfiles/-/raw/master/dist/archlinux/screenshot.png)
![screenshot](https://gitlab.com/pad92/dotfiles/-/raw/master/dist/arch/screenshot.png)


# Install Dotfile
Expand All @@ -21,8 +21,8 @@ curl -sSL https://gitlab.com/pad92/dotfiles/-/raw/master/vim.sh | sh

## My Setup

- [install.md](https://gitlab.com/pad92/dotfiles/-/blob/master/dist/archlinux/install.md)
- [pkglist.txt](https://gitlab.com/pad92/dotfiles/-/tree/master/dist/archlinux/packages/)
- [install.md](https://gitlab.com/pad92/dotfiles/-/blob/master/dist/arch/install.md)
- [pkglist.txt](https://gitlab.com/pad92/dotfiles/-/tree/master/dist/arch/packages/)

# Ubuntu

Expand Down
33 changes: 18 additions & 15 deletions bin/backup.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
#!/bin/sh
. /etc/os-release

MNT_PTS='/mnt/pads918/home'
BACKUP_DIR="${MNT_PTS}/${USERNAME}/backup"
BACKUP_DIR="pascal@192.168.0.100:backup"
HOSTNAME="$(hostnamectl hostname)"

BASEDIR=$(dirname "$0")
TIMESTAMP=$(date "+%Y%m%d-%H%M%S")
RSYNC_OPTS='--archive --perms --xattrs --safe-links --no-specials --no-devices --info=progress2 --delete --delete-excluded'
SUDO_OPTS='-E -s'
if [ ! -d "${BACKUP_DIR}/${HOSTNAME}${HOME}/" ]; then
echo "create ${BACKUP_DIR}/${HOSTNAME}${HOME}/"
sudo mkdir -p "${BACKUP_DIR}/${HOSTNAME}${HOME}/"
fi
PKGLIST_OLD="$(sudo ls -1 ${BACKUP_DIR}/${HOSTNAME}/pkglist-*.txt 2>/dev/null | tail -1)"
PKGLIST_CURRENT="${BACKUP_DIR}/${HOSTNAME}/pkglist-${TIMESTAMP}-${ID}.txt"
#if [ ! -d "${BACKUP_DIR}/${HOSTNAME}${HOME}/" ]; then
# echo "create ${BACKUP_DIR}/${HOSTNAME}${HOME}/"
# sudo mkdir -p "${BACKUP_DIR}/${HOSTNAME}${HOME}/"
#fi
PKGLIST_OLD="$(ls -1 ${BASEDIR}/../dist/${ID}/pkglist-*.txt 2>/dev/null | tail -1)"
PKGLIST_CURRENT="${BASEDIR}/../dist/${ID}/pkglist-${TIMESTAMP}-${ID}.txt"

echo "PKGLIST_OLD : ${PKGLIST_OLD}"
echo "PKGLIST_CURRENT : ${PKGLIST_CURRENT}"

[ -z "${ID_LIKE}" ] && ID_LIKE="${ID}"

Expand All @@ -28,12 +31,12 @@ arch)

yay -Scc --noconfirm

pacman -Qqe | awk '{print $1}' | sudo tee -a ${PKGLIST_CURRENT} 1>/dev/null
pacman -Qqe | awk '{print $1}' | tee -a ${PKGLIST_CURRENT} 1>/dev/null

;;
debian)
sudo apt autoremove --purge
dpkg --get-selections '*' | sudo tee -a ${PKGLIST_CURRENT} 1>/dev/null
dpkg --get-selections '*' | tee -a ${PKGLIST_CURRENT} 1>/dev/null

;;

Expand All @@ -44,14 +47,14 @@ debian)
esac

if [ -s "${PKGLIST_OLD}" ]; then
diff -U 0 "${PKGLIST_OLD}" "${PKGLIST_CURRENT}" > "${BACKUP_DIR}/${HOSTNAME}/pkglist-${TIMESTAMP}.diff"
if [ -s "${BACKUP_DIR}/${HOSTNAME}/pkglist-${TIMESTAMP}.diff" ]; then
cat "${BACKUP_DIR}/${HOSTNAME}/pkglist-${TIMESTAMP}.diff"
diff -U 0 "${PKGLIST_OLD}" "${PKGLIST_CURRENT}" > "${BASEDIR}/../dist/${ID}/pkglist-${TIMESTAMP}.diff"
if [ -s "${BASEDIR}/../dist/${ID}/pkglist-${TIMESTAMP}.diff" ]; then
cat "${BASEDIR}/../dist/${ID}/pkglist-${TIMESTAMP}.diff"
else
rm -f "${BACKUP_DIR}/${HOSTNAME}/pkglist-${TIMESTAMP}.diff"
rm -f "${BASEDIR}/../dist/${ID}/pkglist-${TIMESTAMP}.diff"
fi
fi

sudo rsync ${RSYNC_OPTS} ${HOME}/ ${BACKUP_DIR}/${HOSTNAME}${HOME}/ --exclude-from=- <<- EOF
sudo ${SUDO_OPTS} rsync ${RSYNC_OPTS} ${HOME}/ ${BACKUP_DIR}/${HOSTNAME}${HOME}/ --exclude-from=- <<- EOF
$(cat ${HOME}/.no_backup.txt ${HOME}/.dotfiles/dist/backup_excludes.txt)
EOF
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes

0 comments on commit 2f8e88d

Please sign in to comment.