From b9df08e08dc7eba9352bc68a4d1bb55c8d27529f Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Sun, 28 Nov 2021 15:45:27 +0100 Subject: update --- .backupignore | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 .backupignore (limited to '.backupignore') diff --git a/.backupignore b/.backupignore new file mode 100644 index 0000000..8f44c0d --- /dev/null +++ b/.backupignore @@ -0,0 +1,11 @@ +.Trash/ +*[Cc]ache*/ +.bundle/ +.*[Cc]ache*/ +.cargo/ +.cpan* +.gem/ +.ipfs/ +.npm/ +.vm*/ +go/pkg -- cgit v1.3 From ea345acc22fbb3a0ac36a7d1ea43de3dae0f51a1 Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Thu, 2 Dec 2021 15:26:02 +0100 Subject: update --- .backupignore | 2 ++ .config/kitty/kitty.conf | 5 +++-- .vimrc | 3 ++- bin/backup | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) (limited to '.backupignore') diff --git a/.backupignore b/.backupignore index 8f44c0d..f899501 100644 --- a/.backupignore +++ b/.backupignore @@ -9,3 +9,5 @@ .npm/ .vm*/ go/pkg +*.lock +*.socket diff --git a/.config/kitty/kitty.conf b/.config/kitty/kitty.conf index 3777c68..34dc1b5 100644 --- a/.config/kitty/kitty.conf +++ b/.config/kitty/kitty.conf @@ -24,6 +24,7 @@ #: bold_italic_font Operator Mono Medium Italic # font_size 11.0 +# font_family Fira Code font_size 14.0 #: Font size (in pts) @@ -512,8 +513,8 @@ focus_follows_mouse yes #: Window layout {{{ remember_window_size no -initial_window_width c640 -initial_window_height c480 +initial_window_width 640 +initial_window_height 480 #: If enabled, the window size will be remembered so that new #: instances of kitty will have the same size as the previous diff --git a/.vimrc b/.vimrc index c2a5776..092b7a1 100644 --- a/.vimrc +++ b/.vimrc @@ -41,7 +41,8 @@ let g:netrw_browsex_viewer = "open" let g:netrw_gx = "" let g:netrw_banner = 0 -" autocmd filetype javascript,html,json,yaml set ts=2 sts=2 sw=2 et +" python and yaml formatting: +autocmd filetype python,yaml set ts=2 sts=2 sw=2 et :set wrap :set linebreak diff --git a/bin/backup b/bin/backup index adce78d..9de097f 100755 --- a/bin/backup +++ b/bin/backup @@ -3,7 +3,7 @@ backup() { date=$(date +%Y%m%d_%H%M%S) - last=$(rsync --list-only "$dest/" 2>/dev/null | cut -b 47- | tail -1) + last=$(rsync --list-only "$dest/" 2>/dev/null | awk '{r=$NF} END {print r}') case $last in ([12]*) opt_link=--link-dest=../$last;; -- cgit v1.3 From 0ef8a62a84932a70be06686c55205793921b783b Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Sat, 4 Dec 2021 15:20:25 +0100 Subject: update --- .backupignore | 18 ++++++++++++++++++ .config/kitty/kitty.conf | 1 + 2 files changed, 19 insertions(+) (limited to '.backupignore') diff --git a/.backupignore b/.backupignore index f899501..b4667fa 100644 --- a/.backupignore +++ b/.backupignore @@ -11,3 +11,21 @@ go/pkg *.lock *.socket +*.db-wal +*.db-shm +httpstorages.* +SiriAnalytics.db +Application Support/Knowledge/ +IdentityServices/ +Library/Biome/ +Library/Calendars/ +Library/Saved Application State/ +Containers/com.adguard.* +Containers/com.apple.Safari/ +CoreSpotlight/ +Google/DriveFS/ +GoogleSoftwareUpdate/ +Group Containers/group.com.apple.secure-control-center-preferences/ +Safari/Databases/ +Safari/LocalStorage/ +Safari/Template Icons/ diff --git a/.config/kitty/kitty.conf b/.config/kitty/kitty.conf index 34dc1b5..c79faf1 100644 --- a/.config/kitty/kitty.conf +++ b/.config/kitty/kitty.conf @@ -482,6 +482,7 @@ focus_follows_mouse yes #: Terminal bell {{{ # enable_audio_bell yes +enable_audio_bell no #: Enable/disable the audio bell. Useful in environments that require #: silence. -- cgit v1.3 From 14b5c600034a9d52497af2974f30dafc21710282 Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Mon, 6 Dec 2021 15:36:55 +0100 Subject: update --- .backupignore | 1 + .bashrc | 4 +- bin/backup | 57 ++++++++++++++---------- bin/backup-clean | 132 +++++++++++++++++++++++-------------------------------- 4 files changed, 91 insertions(+), 103 deletions(-) (limited to '.backupignore') diff --git a/.backupignore b/.backupignore index b4667fa..a660b53 100644 --- a/.backupignore +++ b/.backupignore @@ -13,6 +13,7 @@ go/pkg *.socket *.db-wal *.db-shm +*- Google Drive httpstorages.* SiriAnalytics.db Application Support/Knowledge/ diff --git a/.bashrc b/.bashrc index 5c0cdee..c5bdc82 100644 --- a/.bashrc +++ b/.bashrc @@ -38,12 +38,12 @@ export LESS=Rx4 # gnuplot display in terminal export GNUTERM='sixelgd enhanced truecolor font "arial,9"' +export BACKUP=bip:/home/backup/marc@m1 + # Stopwatch alias timer='echo "Timer started. Stop with Ctrl-D." && date && time cat && date' #export TERMINAL=xt - -alias bu='backup -uvd bip:/home/backup/m1' #alias cl='cf xft:Mono:size=12' #alias cp='cp --reflink' #alias ls='ls --color=auto -v' diff --git a/bin/backup b/bin/backup index 9de097f..3964927 100755 --- a/bin/backup +++ b/bin/backup @@ -1,38 +1,47 @@ #!/bin/sh -# Incremental backup using rsync(1). -backup() { - date=$(date +%Y%m%d_%H%M%S) - last=$(rsync --list-only "$dest/" 2>/dev/null | awk '{r=$NF} END {print r}') +usage() { + echo "Usage: $0 [-nv] [[[user@]host]:dir] - case $last in - ([12]*) opt_link=--link-dest=../$last;; - (*) opt_link=;; - esac +Incremental backup using rsync(1). If run as root, a full system +backup is performed. Otherwise, the user's home directory is backed. - rsync -HSxa$optv --exclude-from=$ignore $opt_link $volumes "$dest/$date" -} +Options: +-n dry-run +-v verbose -dest=/.history -ignore=/etc/backupignore -volumes='/ /boot' +Files: +- $HOME/.backupignore exclude files from user backup (non root) +- /etc/backupignore exclude files from system backup (root) + +Environment: +- BACKUP backup directory" +} -while getopts :d:i:nuv opt; do +while getopts :nv opt; do case $opt in - (d) dest="$OPTARG" ;; - (i) ignore="$OPTARG" ;; (n|v) optv="$opt$optv" ;; - (u) optu=1 volumes="$HOME" ignore="$HOME/.backupignore" ;; - (*) echo "Usage: $0 [-nuv] [-d [[user@]host:]dir] [clean|diff]"; exit 1 ;; + (*) usage; exit 1 ;; esac done shift $((OPTIND - 1)) -[ "$optu" ] || [ "$USER" = root ] || exec sudo "$0" "$@" +BACKUP=${1:-$BACKUP} +[ "$BACKUP" ] || { usage; exit 1; } -[ "$1" ] && cmd=$1 && shift || cmd="" -case $cmd in -(""|save) backup ;; -(clean) exec backup-clean ${optv+-$optv} "$@" "$dest";; -(diff) exec diffdir "$@";; +[ "$USER" = root ] && + ignore=/etc/backupignore volumes='/ /boot' || + ignore="$HOME/.backupignore" volumes="$HOME" +[ -f "$ignore" ] && ignore="--exclude-from=$ignore" || ignore= + +last=$(rsync --list-only "$BACKUP/" 2>/dev/null | awk '{r=$NF} END {print r}') +case $last in +([12]*) opt_link=--link-dest=../$last;; +(*) opt_link=;; esac + +date=$(date +%Y-%m-%d-%H%M%S) + +[ "$optv" ] && echo "# Backup $volumes to $BACKUP/$date" + +exec rsync -HSxa$optv $ignore $opt_link $volumes "$BACKUP/$date" diff --git a/bin/backup-clean b/bin/backup-clean index 30d25db..f5baa29 100755 --- a/bin/backup-clean +++ b/bin/backup-clean @@ -1,89 +1,67 @@ #!/bin/sh -# backup garbage collector -[ "$USER" = root ] || exec sudo "$0" "$@" -# Durations, in number of seconds. -hd=3600 # hour duration: 60s * 60 -h12=43200 # 12h: hd * 12 -dd=86400 # day duration: hd * 24 -wd=604800 # week duration: dd * 7 -md=2592000 # month duration: dd * 30 -yd=31557600 # year duration: dd * 365.25 +usage() { + echo "Usage: $0 [-nv] [[[user@]host:]dir] -now=$(date +'%Y%m%d_%H%M%S') +$0 removes old backups and keeps: +- backups for the current day +- 1 backup per past day for the current month +- 1 backup per past month for the current year +- 1 backup per past year -# The following works only for busybox date, not coreutils -# Kept for reference only. -#date2ts() { d=${1%_*} t=${1#*_}; date -d "$d${t%??}" +%s; } +Options: +-n dry run +-v verbose -# Convert date to timestamp, using date from GNU coreutils, -# works also with busybox date. -date2ts() { - t=$1; r=${t#????}; Y=${t%$r} # Year (with century) - t=$r; r=${t#??}; m=${t%$r} # Month - t=$r; r=${t#??}; d=${t%$r} # Day - t=${r#_}; r=${t#??}; H=${t%$r} # Hour - t=$r; r=${t#??}; M=${t%$r} # Minute - S=${t#??} # Second - date -d "$Y-$m-$d $H:$M:$S" +%s - #date -jf "%Y-%m-%d %H:%M:%S" "$Y-$m-$d $H:$M:$S" +%s # BSD, MacOS (not tested) +Environment variables: +- BACKUP - backup directory" } -ts2date() { date -d "@$1" +'%Y%m%d_%H%M%S'; } - -tsn=$(date2ts "$now") - -# Minimal retention delay in seconds, according to backup age, -# implemented using POSIX shell arithmetic. -retention_delay() { - d=$((tsn - $1)) - if [ $((d < h12)) = 1 ]; then - r=0 # keep all backups in the last 12 hours - elif [ $((d < dd)) = 1 ]; then - r=$hd # keep 1 backup per hour in the last day - elif [ $((d < wd)) = 1 ]; then - r=$dd # keep 1 backup per day in the last week - elif [ $((d < md)) = 1 ]; then - r=$wd # keep 1 backup per week in the last month - elif [ $((d < yd)) = 1 ]; then - r=$md # keep 1 backup per month in the last year - else - r=$yd # keep 1 backup per year in the previous years - fi - echo $r -} - -dest=/.history -while getopts :d:nv opt; do +while getopts :nv opt; do case $opt in - (d) tsn=$(date2ts "$OPTARG") ;; - (n) optn=1 ;; - (v) optv=1 ;; - (*) echo "Usage: $0 [-nv] [dir]"; exit 1 ;; + (n) optn=echo ;; + (v) optv=-t ;; + (*) usage; exit 1 ;; esac done -shift $((OPTIND - 1)) -[ "$1" ] && dest=$1 +shift $((OPTIND -1)) + +BACKUP=${1:-$BACKUP} +[ "$BACKUP" ] || { usage; exit 1; } -# Sorted list of backups, most recent first. -lbu=$(ls -rv "$dest") -lasy=${lbu##* +host=${BACKUP%:*} dir=${BACKUP#*:} +ls='ls -r' rm="xargs -r $optv $optn rm -rf" +[ "$host" = "$dir" ] || ls="ssh $host $ls" rm="ssh $host $rm" + +[ "$optv" ] && echo "# Cleaning backups on $BACKUP" + +$ls "$dir" | +awk -v now=$(date +%Y-%m-%d) -v dir="$dir" ' +BEGIN { + yn = substr(now, 1, 4) # Year now + mn = substr(now, 6, 2) # Month now + dn = substr(now, 9, 2) # Day now } -for d in $lbu; do - tsc=$(date2ts "$d") - if ! [ "$tsp" ]; then - [ "$optv" ] && echo "keep $dest/$d" - tsp=$tsc - continue - fi - mrd=$(retention_delay "$tsp") - dp=$((tsp - tsc)) - #if [ $((dp < mrd)) = 1 ]; then - if [ "$d" != "last" -a $((dp < mrd)) = 1 ]; then - [ "$optv" ] && echo "delete $dest/$d" - [ "$optn" ] || rm -rf "${dest:?}/$d" - else - [ "$optv" ] && echo "keep $dest/$d" - tsp=$tsc - fi -done +{ + yb = substr($0, 1, 4) # Year backup + mb = substr($0, 6, 2) # Month backup + db = substr($0, 9, 2) # Day backup + $0 = dir "/" $0 + + dy = yn - yb + dm = dy * 12 + mn - mb + # if (yb != yn) { + if (dm > 12) + if (yb in yearly) print; else yearly[yb] = 1 + next + } + # if (mb != mn) { + dd = dm * 30 + dn - db + if (dd > 30) { + if (mb in monthly) print; else monthly[mb] = 1 + next + } + if (db != dn) { + if (db in dayly) print; else dayly[db] = 1 + } +}' | $rm -- cgit v1.3 From 4233fc9c6bc0f2f136a495efcd497394edd5156b Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Tue, 7 Dec 2021 14:50:57 +0100 Subject: update --- .backupignore | 5 +++++ bin/backup | 3 +-- bin/backup-clean | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) (limited to '.backupignore') diff --git a/.backupignore b/.backupignore index a660b53..3834dfa 100644 --- a/.backupignore +++ b/.backupignore @@ -13,7 +13,12 @@ go/pkg *.socket *.db-wal *.db-shm +*.old +*.log +*.o *- Google Drive +build/*/ +login.keychain-db httpstorages.* SiriAnalytics.db Application Support/Knowledge/ diff --git a/bin/backup b/bin/backup index 3964927..d682849 100755 --- a/bin/backup +++ b/bin/backup @@ -42,6 +42,5 @@ esac date=$(date +%Y-%m-%d-%H%M%S) -[ "$optv" ] && echo "# Backup $volumes to $BACKUP/$date" - +echo "# Backup $volumes to $BACKUP/$date" exec rsync -HSxa$optv $ignore $opt_link $volumes "$BACKUP/$date" diff --git a/bin/backup-clean b/bin/backup-clean index f5baa29..34e6d97 100755 --- a/bin/backup-clean +++ b/bin/backup-clean @@ -33,7 +33,7 @@ host=${BACKUP%:*} dir=${BACKUP#*:} ls='ls -r' rm="xargs -r $optv $optn rm -rf" [ "$host" = "$dir" ] || ls="ssh $host $ls" rm="ssh $host $rm" -[ "$optv" ] && echo "# Cleaning backups on $BACKUP" +echo "# Cleaning backups on $BACKUP" $ls "$dir" | awk -v now=$(date +%Y-%m-%d) -v dir="$dir" ' @@ -51,7 +51,7 @@ BEGIN { dy = yn - yb dm = dy * 12 + mn - mb # if (yb != yn) { - if (dm > 12) + if (dm > 12) { if (yb in yearly) print; else yearly[yb] = 1 next } -- cgit v1.3 From 2285a119864b87bc136035efa6f650d14aacbf12 Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Thu, 9 Dec 2021 20:44:13 +0100 Subject: update --- .backupignore | 2 +- .bash-powerline.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to '.backupignore') diff --git a/.backupignore b/.backupignore index 3834dfa..579b72d 100644 --- a/.backupignore +++ b/.backupignore @@ -18,7 +18,6 @@ go/pkg *.o *- Google Drive build/*/ -login.keychain-db httpstorages.* SiriAnalytics.db Application Support/Knowledge/ @@ -28,6 +27,7 @@ Library/Calendars/ Library/Saved Application State/ Containers/com.adguard.* Containers/com.apple.Safari/ +Containers/com.ranchero.NetNewsWire-Evergreen/ CoreSpotlight/ Google/DriveFS/ GoogleSoftwareUpdate/ diff --git a/.bash-powerline.sh b/.bash-powerline.sh index 626157a..6d2ee2d 100644 --- a/.bash-powerline.sh +++ b/.bash-powerline.sh @@ -23,7 +23,7 @@ __powerline() { elif test -f '/etc/hostname'; then host=$(