snipt

Ctrl+h for KB shortcuts

Bash

Insert SQL via command line

-- insert sql via command line
mysql -u dbuser -p -h dbhost.yoursite.com dbname < /path/to/backup.sql
https://snipt.net/embed/3f22d44f690292f9ca82bfe0d9a4178c/
/raw/3f22d44f690292f9ca82bfe0d9a4178c/
3f22d44f690292f9ca82bfe0d9a4178c
bash
Bash
2
2019-06-05T16:17:26
True
False
False
/api/public/snipt/10646/
insert-sql-via-command-line
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>-- insert sql via <span class="nb">command</span> line </span><span id="L-2"><a name="L-2"></a>mysql -u dbuser -p -h dbhost.yoursite.com dbname &lt; /path/to/backup.sql </span></pre></div> </td></tr></table>
backup, bash, mysql, sql

MySQL

backup a database using date as name file

mysqldump -u <user> -p<pass> <mysite> -r <mysite>-$(date +%d.%b.%Y).sql
https://snipt.net/embed/121c028f636f17324d62bb3d399ea8c1/
/raw/121c028f636f17324d62bb3d399ea8c1/
121c028f636f17324d62bb3d399ea8c1
mysql
MySQL
1
2019-06-14T20:24:53
True
False
False
/api/public/snipt/9688/
backup-a-database-using-date-as-name-file
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="n">mysqldump</span> <span class="o">-</span><span class="n">u</span> <span class="o">&lt;</span><span class="n">user</span><span class="o">&gt;</span> <span class="o">-</span><span class="n">p</span><span class="o">&lt;</span><span class="n">pass</span><span class="o">&gt;</span> <span class="o">&lt;</span><span class="n">mysite</span><span class="o">&gt;</span> <span class="o">-</span><span class="n">r</span> <span class="o">&lt;</span><span class="n">mysite</span><span class="o">&gt;-</span><span class="err">$</span><span class="p">(</span><span class="kt">date</span> <span class="o">+%</span><span class="n">d</span><span class="p">.</span><span class="o">%</span><span class="n">b</span><span class="p">.</span><span class="o">%</span><span class="n">Y</span><span class="p">).</span><span class="k">sql</span> </span></pre></div> </td></tr></table>
backup, mysql, mysqldump

Bash

backup databases from a list of i

1
2
3
mysql -u admin -p`cat /etc/psa/.psa.shadow` psa -e 'SELECT data_bases.name AS "database" FROM data_bases;' > dbnames | sed 's/database//g' dbnames > dbnames2 && cat dbnames2

for i in `cat dbnames2`; do mysqldump --add-drop-table -u admin -p$(cat /etc/psa/.psa.shadow) $i > ${i}-`date +"%m-%d-%y"`.sql; done
https://snipt.net/embed/f3e69c3986a6e8faf0f2d1c02faf229a/
/raw/f3e69c3986a6e8faf0f2d1c02faf229a/
f3e69c3986a6e8faf0f2d1c02faf229a
bash
Bash
4
2019-06-13T14:39:18
True
False
False
/api/public/snipt/9430/
backup-databases-from-a-list-of-i
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>mysql -u admin -p<span class="sb">`</span>cat /etc/psa/.psa.shadow<span class="sb">`</span> psa -e <span class="s1">&#39;SELECT data_bases.name AS &quot;database&quot; FROM data_bases;&#39;</span> &gt; dbnames <span class="p">|</span> sed <span class="s1">&#39;s/database//g&#39;</span> dbnames &gt; dbnames2 <span class="o">&amp;&amp;</span> cat dbnames2 </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a><span class="k">for</span> i in <span class="sb">`</span>cat dbnames2<span class="sb">`</span><span class="p">;</span> <span class="k">do</span> mysqldump --add-drop-table -u admin -p<span class="k">$(</span>cat /etc/psa/.psa.shadow<span class="k">)</span> <span class="nv">$i</span> &gt; <span class="si">${</span><span class="nv">i</span><span class="si">}</span>-<span class="sb">`</span>date +<span class="s2">&quot;%m-%d-%y&quot;</span><span class="sb">`</span>.sql<span class="p">;</span> <span class="k">done</span> </span></pre></div> </td></tr></table>
backup, databases, for, i

Bash

time machine interval

$sudo defaults write /System/Library/LaunchDaemons/com.apple.backupd-auto StartInterval -int 14400
https://snipt.net/embed/8683ab93b2ec3fba2a9e4d2dcf2273bd/
/raw/8683ab93b2ec3fba2a9e4d2dcf2273bd/
8683ab93b2ec3fba2a9e4d2dcf2273bd
bash
Bash
1
2019-05-31T11:26:39
True
False
False
/api/public/snipt/8351/
time-machine-interval
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="nv">$sudo</span> defaults write /System/Library/LaunchDaemons/com.apple.backupd-auto StartInterval -int 14400 </span></pre></div> </td></tr></table>
backup, osx

Text only

Locally backup remote files via ssh

ssh [email protected] "cd /; tar -cvf - / | gzip -c" > backup.tar.gz
https://snipt.net/embed/297989ab56fd9e9a35943e45b09b5172/
/raw/297989ab56fd9e9a35943e45b09b5172/
297989ab56fd9e9a35943e45b09b5172
text
Text only
1
2019-06-13T11:56:33
True
False
False
/api/public/snipt/7473/
locally-backup-remote-files-via-ssh
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>ssh [email protected] &quot;cd /; tar -cvf - / | gzip -c&quot; &gt; backup.tar.gz </span></pre></div> </td></tr></table>
backup, gzip, ssh, tar, tarball

Bash

Restore and Import MySQL dump

mysql -u username -ppassword database_name < dump.sql
https://snipt.net/embed/db660354aadf4edae6b81839c8a29ff4/
/raw/db660354aadf4edae6b81839c8a29ff4/
db660354aadf4edae6b81839c8a29ff4
bash
Bash
1
2019-06-13T19:38:34
True
False
False
/api/public/snipt/6904/
restore-and-import-mysql-dump
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>mysql -u username -ppassword database_name &lt; dump.sql </span></pre></div> </td></tr></table>
archive, backup, mysql, shell

Bash

Backup ALL MySQL DBs

mysqldump -u username -ppassword –all-databases > dump.sql
https://snipt.net/embed/a427e3c7f3e7597add52df495bb61454/
/raw/a427e3c7f3e7597add52df495bb61454/
a427e3c7f3e7597add52df495bb61454
bash
Bash
1
2019-06-15T05:52:15
True
False
False
/api/public/snipt/6903/
backup-all-mysql-dbs
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>mysqldump -u username -ppassword –all-databases &gt; dump.sql </span></pre></div> </td></tr></table>
archive, backup, mysql, shell