Content-Security-Policy: default-src 'none'
Content-Type: text/plain; charset=UTF-8
Content-Length: 1991
Content-Disposition: inline; filename="backup.sh"
Last-Modified: Thu, 27 Feb 2025 04:13:46 GMT
Expires: Sun, 25 Feb 2035 04:13:46 GMT
ETag: "5a898fbfe64bd7256754bb388715668dfb3453c6"

#! /bin/bash
set -e

backup_local() {
	# external program to supply the passphrase:
	export BORG_PASSCOMMAND="pass show $1" # repo pass first arg

	# Create Local Backups
	echo "$(date) -- Creating Local Backups ..."
	REPOSITORY=$2 # repo vault path second arg
	shift 2       # consume the first 2 arguments
	borg create --list --filter AME --stats --compression=lz4 \
		--progress \
		--exclude '*.pyc' \
		--exclude '*/.mypy_cache/' \
		--exclude '*/venv/' \
		--exclude '*/python*/site-packages/' \
		--exclude '*/.tox/' \
		--exclude '*/node_modules' \
		--exclude '*/dist' \
		--exclude '*/.cache' \
		--exclude '*/cache' \
		--exclude '*/.shadow-cljs' \
		--exclude '*/js/compiled' \
		--exclude '*/build' \
		--exclude '*/target' \
		--exclude '*/dist-newstyle' \
		--exclude '*/.notmuch' \
		--exclude '*/mpd/log' \
		--exclude '*/elpa' \
		--exclude '*.elc' \
		--exclude '*/*.o' \
		--exclude '*/guix/*/*.go' \
		--exclude '*/guix/*/*.Po' \
		--exclude '*/guix/*/*.m4' \
		--exclude '*/.local/straight' \
		--exclude '*/phd/simulation_data' \
		--exclude '*/semantic-roam' \
		"$REPOSITORY::{hostname}-{user}-{utcnow:%Y-%m-%dT%H:%M:%S}" \
		"$@" # all the dirs to bac

	# Prune Local Backups
	echo "$(date) -- Pruning local repository ..."

	borg prune --verbose --stats --list \
		--glob-archives='{hostname}-{user}-*' \
		--keep-daily 7 \
		--keep-weekly 4 \
		--keep-monthly 6 "$REPOSITORY"
}

BASIC_PATHS=(~/dev/ ~/org/ ~/.mail/ ~/.bogofilter/ ~/Nextcloud/)
backup_local Admin/sarah/borg/ingrid ssh://borgbackup@nina/./repos/ingrid "${BASIC_PATHS[@]}"

DISK=/run/media/titan/ext_backup
if [ -d "$DISK" ]; then
	LARGER_PATHS=("$DISK/personal/Pictures/" "$DISK/personal/Libros/" "$DISK/personal/dev/" "$DISK/Archives/")
	backup_local Admin/sarah/borg/oscar ssh://borgbackup@nina/./repos/oscar "${LARGER_PATHS[@]}"
	if ping -c 1 -W 1 192.168.178.40 >/dev/null; then
		backup_local borgbackup ssh://backup/media/Backup/daily_backup/ "${BASIC_PATHS[@]}" "${LARGER_PATHS[@]}"
	fi
fi
th'>path: <a href='/dotfiles/tree/?id=1a4e6e590bd33595e8d6fe497d4b0e940f9594c1'>root</a>/<a href='/dotfiles/tree/bin?id=1a4e6e590bd33595e8d6fe497d4b0e940f9594c1'>bin</a>/<a href='/dotfiles/tree/bin/backup.sh?id=1a4e6e590bd33595e8d6fe497d4b0e940f9594c1'>backup.sh</a></div><div class='content'>blob: d70ed1907781b623cd8f7266076a1f5ebcfe4ee4 (<a href='/dotfiles/plain/bin/backup.sh?id=1a4e6e590bd33595e8d6fe497d4b0e940f9594c1'>plain</a>)
<table summary='blob content' class='blob'>
<tr><td class='linenumbers'><pre><a id='n1' href='#n1'>1</a>
<a id='n2' href='#n2'>2</a>
<a id='n3' href='#n3'>3</a>
<a id='n4' href='#n4'>4</a>
<a id='n5' href='#n5'>5</a>
<a id='n6' href='#n6'>6</a>
<a id='n7' href='#n7'>7</a>
<a id='n8' href='#n8'>8</a>
<a id='n9' href='#n9'>9</a>
<a id='n10' href='#n10'>10</a>
<a id='n11' href='#n11'>11</a>
<a id='n12' href='#n12'>12</a>
<a id='n13' href='#n13'>13</a>
<a id='n14' href='#n14'>14</a>
<a id='n15' href='#n15'>15</a>
<a id='n16' href='#n16'>16</a>
<a id='n17' href='#n17'>17</a>
<a id='n18' href='#n18'>18</a>
<a id='n19' href='#n19'>19</a>
<a id='n20' href='#n20'>20</a>
<a id='n21' href='#n21'>21</a>
<a id='n22' href='#n22'>22</a>
<a id='n23' href='#n23'>23</a>
<a id='n24' href='#n24'>24</a>
<a id='n25' href='#n25'>25</a>
<a id='n26' href='#n26'>26</a>
<a id='n27' href='#n27'>27</a>
<a id='n28' href='#n28'>28</a>
<a id='n29' href='#n29'>29</a>
<a id='n30' href='#n30'>30</a>
<a id='n31' href='#n31'>31</a>
<a id='n32' href='#n32'>32</a>
<a id='n33' href='#n33'>33</a>
<a id='n34' href='#n34'>34</a>
<a id='n35' href='#n35'>35</a>
<a id='n36' href='#n36'>36</a>
<a id='n37' href='#n37'>37</a>
<a id='n38' href='#n38'>38</a>
<a id='n39' href='#n39'>39</a>
<a id='n40' href='#n40'>40</a>
<a id='n41' href='#n41'>41</a>
<a id='n42' href='#n42'>42</a>
</pre></td>
<td class='lines'><pre><code><style>pre { line-height: 125%; }
td.linenos .normal { color: #37474F; background-color: #263238; padding-left: 5px; padding-right: 5px; }
span.linenos { color: #37474F; background-color: #263238; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #607A86; background-color: #263238; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #607A86; background-color: #263238; padding-left: 5px; padding-right: 5px; }
.highlight .hll { background-color: #2C3B41 }
.highlight { background: #263238; color: #EEFFFF }
.highlight .c { color: #546E7A; font-style: italic } /* Comment */
.highlight .err { color: #FF5370 } /* Error */
.highlight .esc { color: #89DDFF } /* Escape */
.highlight .g { color: #EEFFFF } /* Generic */
.highlight .k { color: #BB80B3 } /* Keyword */
.highlight .l { color: #C3E88D } /* Literal */
.highlight .n { color: #EEFFFF } /* Name */
.highlight .o { color: #89DDFF } /* Operator */
.highlight .p { color: #89DDFF } /* Punctuation */
.highlight .ch { color: #546E7A; font-style: italic } /* Comment.Hashbang */
.highlight .cm { color: #546E7A; font-style: italic } /* Comment.Multiline */
.highlight .cp { color: #546E7A; font-style: italic } /* Comment.Preproc */
.highlight .cpf { color: #546E7A; font-style: italic } /* Comment.PreprocFile */
.highlight .c1 { color: #546E7A; font-style: italic } /* Comment.Single */
.highlight .cs { color: #546E7A; font-style: italic } /* Comment.Special */
.highlight .gd { color: #FF5370 } /* Generic.Deleted */
.highlight .ge { color: #89DDFF } /* Generic.Emph */
.highlight .ges { color: #FFCB6B } /* Generic.EmphStrong */
.highlight .gr { color: #FF5370 } /* Generic.Error */
.highlight .gh { color: #C3E88D } /* Generic.Heading */
.highlight .gi { color: #C3E88D } /* Generic.Inserted */
.highlight .go { color: #546E7A } /* Generic.Output */
.highlight .gp { color: #FFCB6B } /* Generic.Prompt */
.highlight .gs { color: #FF5370 } /* Generic.Strong */
.highlight .gu { color: #89DDFF } /* Generic.Subheading */
.highlight .gt { color: #FF5370 } /* Generic.Traceback */
.highlight .kc { color: #89DDFF } /* Keyword.Constant */
.highlight .kd { color: #BB80B3 } /* Keyword.Declaration */
.highlight .kn { color: #89DDFF; font-style: italic } /* Keyword.Namespace */
.highlight .kp { color: #89DDFF } /* Keyword.Pseudo */
.highlight .kr { color: #BB80B3 } /* Keyword.Reserved */
.highlight .kt { color: #BB80B3 } /* Keyword.Type */
.highlight .ld { color: #C3E88D } /* Literal.Date */
.highlight .m { color: #F78C6C } /* Literal.Number */
.highlight .s { color: #C3E88D } /* Literal.String */
.highlight .na { color: #BB80B3 } /* Name.Attribute */
.highlight .nb { color: #82AAFF } /* Name.Builtin */
.highlight .nc { color: #FFCB6B } /* Name.Class */
.highlight .no { color: #EEFFFF } /* Name.Constant */
.highlight .nd { color: #82AAFF } /* Name.Decorator */
.highlight .ni { color: #89DDFF } /* Name.Entity */
.highlight .ne { color: #FFCB6B } /* Name.Exception */
.highlight .nf { color: #82AAFF } /* Name.Function */
.highlight .nl { color: #82AAFF } /* Name.Label */
.highlight .nn { color: #FFCB6B } /* Name.Namespace */
.highlight .nx { color: #EEFFFF } /* Name.Other */
.highlight .py { color: #FFCB6B } /* Name.Property */
.highlight .nt { color: #FF5370 } /* Name.Tag */
.highlight .nv { color: #89DDFF } /* Name.Variable */
.highlight .ow { color: #89DDFF; font-style: italic } /* Operator.Word */
.highlight .pm { color: #89DDFF } /* Punctuation.Marker */
.highlight .w { color: #EEFFFF } /* Text.Whitespace */
.highlight .mb { color: #F78C6C } /* Literal.Number.Bin */
.highlight .mf { color: #F78C6C } /* Literal.Number.Float */
.highlight .mh { color: #F78C6C } /* Literal.Number.Hex */
.highlight .mi { color: #F78C6C } /* Literal.Number.Integer */
.highlight .mo { color: #F78C6C } /* Literal.Number.Oct */
.highlight .sa { color: #BB80B3 } /* Literal.String.Affix */
.highlight .sb { color: #C3E88D } /* Literal.String.Backtick */
.highlight .sc { color: #C3E88D } /* Literal.String.Char */
.highlight .dl { color: #EEFFFF } /* Literal.String.Delimiter */
.highlight .sd { color: #546E7A; font-style: italic } /* Literal.String.Doc */
.highlight .s2 { color: #C3E88D } /* Literal.String.Double */
.highlight .se { color: #EEFFFF } /* Literal.String.Escape */
.highlight .sh { color: #C3E88D } /* Literal.String.Heredoc */
.highlight .si { color: #89DDFF } /* Literal.String.Interpol */
.highlight .sx { color: #C3E88D } /* Literal.String.Other */
.highlight .sr { color: #89DDFF } /* Literal.String.Regex */
.highlight .s1 { color: #C3E88D } /* Literal.String.Single */
.highlight .ss { color: #89DDFF } /* Literal.String.Symbol */
.highlight .bp { color: #89DDFF } /* Name.Builtin.Pseudo */
.highlight .fm { color: #82AAFF } /* Name.Function.Magic */
.highlight .vc { color: #89DDFF } /* Name.Variable.Class */
.highlight .vg { color: #89DDFF } /* Name.Variable.Global */
.highlight .vi { color: #89DDFF } /* Name.Variable.Instance */
.highlight .vm { color: #82AAFF } /* Name.Variable.Magic */
.highlight .il { color: #F78C6C } /* Literal.Number.Integer.Long */</style><div class="highlight"><pre><span></span><span class="ch">#! /bin/bash</span>

backup_local<span class="o">()</span><span class="w"> </span><span class="o">{</span>
<span class="w">	</span><span class="c1"># external program to supply the passphrase:</span>
<span class="w">	</span><span class="nb">export</span><span class="w"> </span><span class="nv">BORG_PASSCOMMAND</span><span class="o">=</span><span class="s2">&quot;pass show </span><span class="nv">$1</span><span class="s2">&quot;</span><span class="w"> </span><span class="c1"># repo pass first arg</span>

<span class="w">	</span><span class="c1"># Create Local Backups</span>
<span class="w">	</span><span class="nb">echo</span><span class="w"> </span><span class="k">$(</span>date<span class="k">)</span><span class="w"> </span><span class="s2">&quot;Creating Local Backups ...&quot;</span>
<span class="w">	</span><span class="nv">REPOSITORY</span><span class="o">=</span><span class="nv">$2</span><span class="w"> </span><span class="c1"># repo vault path second arg</span>
<span class="w">	</span><span class="nb">shift</span><span class="w"> </span><span class="m">2</span><span class="w">       </span><span class="c1"># consume the first 2 arguments</span>
<span class="w">	</span>borg<span class="w"> </span>create<span class="w"> </span>--list<span class="w"> </span>--filter<span class="w"> </span>AME<span class="w"> </span>--stats<span class="w"> </span>--compression<span class="o">=</span>lz4<span class="w"> </span><span class="se">\</span>
<span class="w">		</span>--progress<span class="w"> </span><span class="se">\</span>
<span class="w">		</span>--exclude<span class="w"> </span><span class="s1">&#39;*.pyc&#39;</span><span class="w"> </span><span class="se">\</span>
<span class="w">		</span>--exclude<span class="w"> </span><span class="s1">&#39;*/.mypy_cache/&#39;</span><span class="w"> </span><span class="se">\</span>
<span class="w">		</span>--exclude<span class="w"> </span><span class="s1">&#39;*/venv/&#39;</span><span class="w"> </span><span class="se">\</span>
<span class="w">		</span>--exclude<span class="w"> </span><span class="s1">&#39;*/.tox/&#39;</span><span class="w"> </span><span class="se">\</span>
<span class="w">		</span>--exclude<span class="w"> </span><span class="s1">&#39;*/node_modules&#39;</span><span class="w"> </span><span class="se">\</span>
<span class="w">		</span>--exclude<span class="w"> </span><span class="s1">&#39;*/js/compiled&#39;</span><span class="w"> </span><span class="se">\</span>
<span class="w">		</span>--exclude<span class="w"> </span><span class="s1">&#39;*/target&#39;</span><span class="w"> </span><span class="se">\</span>
<span class="w">		</span>--exclude<span class="w"> </span><span class="s1">&#39;*/dist-newstyle&#39;</span><span class="w"> </span><span class="se">\</span>
<span class="w">		</span>--exclude<span class="w"> </span><span class="s1">&#39;*/.notmuch&#39;</span><span class="w"> </span><span class="se">\</span>
<span class="w">		</span>--exclude<span class="w"> </span><span class="s1">&#39;*/mpd/log&#39;</span><span class="w"> </span><span class="se">\</span>
<span class="w">		</span>--exclude<span class="w"> </span><span class="s1">&#39;*/elpa&#39;</span><span class="w"> </span><span class="se">\</span>
<span class="w">		</span>--exclude<span class="w"> </span><span class="s1">&#39;*.elc&#39;</span><span class="w"> </span><span class="se">\</span>
<span class="w">		</span>--exclude<span class="w"> </span><span class="s1">&#39;*/.local/straight&#39;</span><span class="w"> </span><span class="se">\</span>
<span class="w">		</span><span class="nv">$REPOSITORY</span>::<span class="s1">&#39;{hostname}-{user}-{utcnow:%Y-%m-%dT%H:%M:%S}&#39;</span><span class="w"> </span><span class="se">\</span>
<span class="w">		</span><span class="nv">$@</span><span class="w"> </span><span class="c1"># all the dirs to bac</span>

<span class="w">	</span><span class="c1"># Prune Local Backups</span>
<span class="w">	</span><span class="nb">echo</span><span class="w"> </span><span class="k">$(</span>date<span class="k">)</span><span class="w"> </span><span class="s2">&quot;Pruning local repository ...&quot;</span>

<span class="w">	</span>borg<span class="w"> </span>prune<span class="w"> </span>--verbose<span class="w"> </span>--stats<span class="w"> </span>--list<span class="w"> </span><span class="se">\</span>
<span class="w">		</span>--prefix<span class="o">=</span><span class="s1">&#39;{hostname}-{user}-&#39;</span><span class="w"> </span><span class="se">\</span>
<span class="w">		</span>--keep-daily<span class="w"> </span><span class="m">7</span><span class="w"> </span><span class="se">\</span>
<span class="w">		</span>--keep-weekly<span class="w"> </span><span class="m">4</span><span class="w"> </span><span class="se">\</span>
<span class="w">		</span>--keep-monthly<span class="w"> </span><span class="m">6</span><span class="w"> </span><span class="nv">$REPOSITORY</span>
<span class="o">}</span>

<span class="nv">DISK</span><span class="o">=</span>/run/media/titan/ext_backup
backup_local<span class="w"> </span>borgbackup<span class="w"> </span>ssh://backup/media/Backup/daily_backup/<span class="w"> </span>~/dev/<span class="w"> </span>~/.mail/<span class="w"> </span>~/Nextcloud/<span class="w"> </span>~/org/<span class="w"> </span><span class="s2">&quot;</span><span class="nv">$DISK</span><span class="s2">/personal/Pictures/&quot;</span><span class="w"> </span><span class="s2">&quot;</span><span class="nv">$DISK</span><span class="s2">/personal/Libros/&quot;</span><span class="w"> </span><span class="s2">&quot;</span><span class="nv">$DISK</span><span class="s2">/personal/dev/&quot;</span><span class="w"> </span><span class="s2">&quot;</span><span class="nv">$DISK</span><span class="s2">/Archives/&quot;</span>
backup_local<span class="w"> </span>Admin/sarah/borg/ingrid<span class="w"> </span>ssh://borgbackup@173.212.211.30/./repos/ingrid<span class="w"> </span>~/dev/<span class="w"> </span>~/org/<span class="w"> </span>~/.mail/<span class="w"> </span>~/Nextcloud/
backup_local<span class="w"> </span>Admin/sarah/borg/oscar<span class="w"> </span>ssh://borgbackup@173.212.211.30/./repos/oscar<span class="w"> </span><span class="s2">&quot;</span><span class="nv">$DISK</span><span class="s2">/personal/Pictures/&quot;</span><span class="w"> </span><span class="s2">&quot;</span><span class="nv">$DISK</span><span class="s2">/personal/Libros/&quot;</span><span class="w"> </span><span class="s2">&quot;</span><span class="nv">$DISK</span><span class="s2">/personal/dev/&quot;</span><span class="w"> </span><span class="s2">&quot;</span><span class="nv">$DISK</span><span class="s2">/Archives/&quot;</span>
</pre></div>
</code></pre></td></tr></table>
</div> <!-- class=content -->
<div class='footer'>generated by <a href='https://git.zx2c4.com/cgit/about/'>cgit v1.2.3</a> (<a href='https://git-scm.com/'>git 2.43.2</a>) at 2025-02-27 04:13:47 +0000</div>
</div> <!-- id=cgit -->
</body>
</html>
