Files
mkdocs/docs/Raspberry/backup.md
Bruno 21 e82296ba06 1er commit
De la docs au format Mkdocs
2018-09-16 14:48:15 +02:00

99 lines
2.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Backup
### Avec sshpass (MdP en clair)
```bash
$ sudo apt-get install sshpass
```
```bash
\#!/bin/bash
sudo sshpass -p "password" rsync -avzO --exclude='@eaDir' -e ssh bruno@192.168.1.7:/var/services/homes/bruno/CloudStation/Drive/Raspberry :/var/services/homes/bruno/CloudStation/Drive/Unix /home/pi/Documents
```
Sauver avec CTRL-O (Return) et quitter avec CTRL-X (Return)
### Par clé
```bash
$ ssh-keygen -t rsa -C pi@framboise
$ cat ~/.ssh/id_rsa.pub | ssh bruno@192.168.1.7 -p42666 'cat >> .ssh/authorized_keys'
```
```bash
\#!/bin/bash
rsync -avzO --exclude='@eaDir' -e ssh bruno@192.168.1.7:/var/services/homes/bruno/CloudStation/Drive/Raspberry :/var/services/homes/bruno/CloudStation/Drive/Unix /home/pi/Documents
\# option -O pour éviter lerreur:
\# rsync: failed to set times on "/home/pi/Documents/Unix": Operation not permitted (1)
```
Sauver avec CTRL-O (Return) et quitter avec CTRL-X (Return)
Rendre le script exécutable
```
$ sudo chmod +x /home/pi/sync.sh
```
### Ajouter le script à cron:
Créer une crontab pour l'utilisateur pi
```bash
pi@framboise:~ $ crontab -u pi -e
no crontab for pi - using an empty one
Select an editor. To change later, run 'select-editor'.
1. /bin/ed
2. /bin/nano <---- easiest
3. /usr/bin/vim.tiny
Choose 1-3 [2]: 2
crontab: installing new crontab
```
Editer la crontab utilisateur (pi)
```bash
$ pi@framboise:~ $ crontab -e
```
Ajouter la ligne
`*/5 * * * * /home/pi/Documents/sync.sh >> /home/pi/sync.log 2>&1`
Le script sync.sh est exécuté toutes les 5mn.
STDOUT est redirigé sur sync.log et STDERR aussi.
Redirection du flux de sortie (STDOUT): >/dev/null
Rediriger uniquement STDERR: 2>/dev/null
Rediriger STDERR là où est redirigé STDOUT: 2>&1
Si les sorties ne sont redirigées, erreur dans /var/syslog
```bash
CRON[8380]: (CRON) info (No MTA installed, discarding output)
(pas de Mail Transfer Agent, ie Postfix, Mutt…)
```
Lire la crontab utilisateur (pi)
```bash
pi@framboise:~ $ crontab -l
```