A barra final + a parte ausente do caminho me mordeu, digitando o pequeno exemplo ajudou.
A solução é que a barra final deve ser adicionada ao $SOURCE
e media
precisa ser adicionado ao eventual $TARGET
.
Eu criei um script de backup que deve criar backups incrementais todos os dias e um backup completo uma vez por semana, de um host remoto para meu disco rígido de backup externo.
(pequeno exemplo na parte inferior)
O script ( link ):
#!/bin/env bash
#
# Adapted from http://webgnuru.com/linux/rsync_incremental.php
#
USER='modelbrouw'
HOST='modelbrouwers.nl'
DAYS_BETWEEN_FULL=30 # number of days between full backups.
TARGET_SUFFIX="media"
TARGET_BASE="/run/media/bbt/40d67de8-f4b6-4707-9947-f96f44efd7bf/"
SOURCE="/home/modelbrouw/django/production/$TARGET_SUFFIX"
today='date -I'
prev_day=$today # check if backup from today exists
get_target() {
root_dir=$TARGET_BASE$1
if [[ $2 ]]; then
root_dir=$root_dir/$2
fi
echo $root_dir
}
LOG='get_target $today 'rsync_inc.log''
# do the date calculations
# determine if a full/incremental backup should be taken
run_backup() {
i=0
PREV_BACKUP='get_target $prev_day'
while [ $i -lt 100 ] && [ ! -d $PREV_BACKUP ]
do
i=$[i+1]
prev_day='date -I -d "$i day ago"'
PREV_BACKUP='get_target $prev_day'
done
if [ $i -eq '0' ]; then
echo "Backup already created"
# exit
else
echo $i 'days since last backup'
fi
# create the target directory
TARGET='get_target $today'
echo -e 'Backup target:' $TARGET "\n"
mkdir -p $TARGET
if [ $i -lt $DAYS_BETWEEN_FULL ]; then
echo -e "creating incremental backup, based on" $prev_day "\n"
incremental_backup
else
echo -e "creating full backup \n"
source ./backup.sh
fi
}
incremental_backup() {
DEST='get_target $today $TARGET_SUFFIX'
COMP='get_target $prev_day $TARGET_SUFFIX'
echo 'remote source directory:' $SOURCE
echo 'backup destination:' $DEST
SSH="-e ssh $USER@$HOST:$SOURCE"
OPT="-rvLtShP"
echo $LOG
rsync $OPT --link-dest=$COMP $SSH $TARGET > $LOG
}
run_backup
O que é suposto fazer Basicamente o que cria uma pasta de destino para o backup com a data de hoje, procure pelo backup anterior (subtraia um dia da data anterior até que uma pasta seja encontrada, pois não posso executar o backup todos os dias / noite) e se 7 dias decorridos, será criado um backup completo.
Esse backup é bem grande, então eu quero usar --link-dest para criar hard links para o backup anterior se o arquivo não tiver mudado.
O host remoto é acessado com ssh sem senha, nada de especial acontecendo aqui.
O que faz
O comportamento observado é que o backup é realmente criado corretamente, mas nenhum link físico é criado, mesmo que os arquivos pareçam ser idênticos.
Informações úteis em potencial
Algumas informações possivelmente mais relacionadas:
O que mais eu tentei
Eu rodei o rsync com as mesmas opções e via ssh na minha máquina local com as pastas / home / bbt / teste / source, / home / bbt / teste / prev, / home / bbt / test / target. Os arquivos da pasta target
realmente têm links para os arquivos da pasta prev
, como esperado.
Saída do backup em execução no momento
➜ scripts ./run_backup.sh
2 days since last backup
Backup target: /run/media/bbt/40d67de8-f4b6-4707-9947-f96f44efd7bf/2015-10-24
creating incremental backup, based on 2015-10-22
remote source directory: /home/modelbrouw/django/production/media
backup destination: /run/media/bbt/40d67de8-f4b6-4707-9947-f96f44efd7bf/2015-10-24/media
Depois fui verificar um arquivo de teste:
➜ 1 pwd
/run/media/bbt/40d67de8-f4b6-4707-9947-f96f44efd7bf/2015-10-22/media/albums/1/1
➜ 1 stat 1024_chameleon.jpg
File: ‘1024_chameleon.jpg’
Size: 31694 Blocks: 64 IO Block: 4096 regular file
Device: 811h/2065d Inode: 81264905 Links: 1
Access: (0645/-rw-r--r-x) Uid: ( 1000/ bbt) Gid: ( 1000/ bbt)
Access: 2015-10-22 20:32:09.550197848 +0200
Modify: 2012-07-04 19:13:10.000000000 +0200
Change: 2015-10-22 20:32:09.550197848 +0200
Birth: -
E verifique o arquivo correspondente no novo backup - aqui eu esperaria um link físico:
➜ 1 pwd
/run/media/bbt/40d67de8-f4b6-4707-9947-f96f44efd7bf/2015-10-24/media/albums/1/1
➜ 1 stat 1024_chameleon.jpg
File: ‘1024_chameleon.jpg’
Size: 31694 Blocks: 64 IO Block: 4096 regular file
Device: 811h/2065d Inode: 107348180 Links: 1
Access: (0645/-rw-r--r-x) Uid: ( 1000/ bbt) Gid: ( 1000/ bbt)
Access: 2015-10-24 17:07:01.695760211 +0200
Modify: 2012-07-04 19:13:10.000000000 +0200
Change: 2015-10-24 17:00:34.284219203 +0200
Birth: -
Por fim, eu registro toda a saída do rsync, assim, o cabeçalho do arquivo é assim:
➜ 2015-10-24 head rsync_inc.log -n 100
receiving incremental file list
media/
media/.htaccess
49 100% 47.85kB/s 0:00:00 (xfr#1, ir-chk=1114/1116)
media/albums/
media/albums/1/
media/albums/1/1/
media/albums/1/1/1024_Foto0551.jpg
74.35K 100% 77.74kB/s 0:00:00 (xfr#2, ir-chk=1276/2436)
media/albums/1/1/1024_Foto0552.jpg
81.28K 100% 82.26kB/s 0:00:00 (xfr#3, ir-chk=1275/2436)
media/albums/1/1/1024_Foto0553.jpg
59.76K 100% 59.68kB/s 0:00:00 (xfr#4, ir-chk=1274/2436)
media/albums/1/1/1024_Foto0554.jpg
100.46K 100% 97.32kB/s 0:00:01 (xfr#5, ir-chk=1273/2436)
media/albums/1/1/1024_Foto0555.jpg
105.82K 100% 3.15MB/s 0:00:00 (xfr#6, ir-chk=1272/2436)
media/albums/1/1/1024_Foto0556.jpg
82.08K 100% 1.53MB/s 0:00:00 (xfr#7, ir-chk=1271/2436)
media/albums/1/1/1024_chameleon.jpg
31.69K 100% 562.75kB/s 0:00:00 (xfr#8, ir-chk=1270/2436)
media/albums/1/1/Foto0551.jpg
49.58K 100% 691.70kB/s 0:00:00 (xfr#9, ir-chk=1269/2436)
media/albums/1/1/Foto0552.jpg
55.32K 100% 675.32kB/s 0:00:00 (xfr#10, ir-chk=1268/2436)
media/albums/1/1/Foto0553.jpg
41.20K 100% 410.56kB/s 0:00:00 (xfr#11, ir-chk=1267/2436)
media/albums/1/1/Foto0554.jpg
67.87K 100% 597.15kB/s 0:00:00 (xfr#12, ir-chk=1266/2436)
media/albums/1/1/Foto0555.jpg
69.35K 100% 559.73kB/s 0:00:00 (xfr#13, ir-chk=1265/2436)
media/albums/1/1/Foto0556.jpg
56.50K 100% 396.95kB/s 0:00:00 (xfr#14, ir-chk=1264/2436)
media/albums/1/1/chameleon.jpg
20.77K 100% 145.92kB/s 0:00:00 (xfr#15, ir-chk=1263/2436)
media/albums/1/1/thumb_Foto0551.jpg
2.41K 100% 16.82kB/s 0:00:00 (xfr#16, ir-chk=1262/2436)
media/albums/1/1/thumb_Foto0552.jpg
2.57K 100% 17.95kB/s 0:00:00 (xfr#17, ir-chk=1261/2436)
media/albums/1/1/thumb_Foto0553.jpg
2.37K 100% 16.50kB/s 0:00:00 (xfr#18, ir-chk=1260/2436)
media/albums/1/1/thumb_Foto0554.jpg
3.21K 100% 21.33kB/s 0:00:00 (xfr#19, ir-chk=1259/2436)
media/albums/1/1/thumb_Foto0555.jpg
2.94K 100% 19.56kB/s 0:00:00 (xfr#20, ir-chk=1258/2436)
media/albums/1/1/thumb_Foto0556.jpg
2.91K 100% 19.31kB/s 0:00:00 (xfr#21, ir-chk=1257/2436)
media/albums/1/1/thumb_chameleon.jpg
1.45K 100% 9.60kB/s 0:00:00 (xfr#22, ir-chk=1256/2436)
media/albums/1/14/
media/albums/1/14/2012-07-28 20.46.38.jpg
89.52K 100% 526.65kB/s 0:00:00 (xfr#23, ir-chk=1255/2436)
media/albums/1/14/2012-07-28 20.46.50.jpg
99.56K 100% 522.70kB/s 0:00:00 (xfr#24, ir-chk=1254/2436)
media/albums/1/14/2012-07-28 20.47.49.jpg
121.80K 100% 553.25kB/s 0:00:00 (xfr#25, ir-chk=1253/2436)
media/albums/1/14/2012-07-28 20.47.59.jpg
117.66K 100% 476.78kB/s 0:00:00 (xfr#26, ir-chk=1252/2436)
media/albums/1/14/2012-07-28 20.48.06.jpg
101.82K 100% 380.98kB/s 0:00:00 (xfr#27, ir-chk=1251/2436)
media/albums/1/14/thumb_2012-07-28 20.46.38.jpg
6.99K 100% 26.16kB/s 0:00:00 (xfr#28, ir-chk=1250/2436)
media/albums/1/14/thumb_2012-07-28 20.46.50.jpg
7.55K 100% 28.25kB/s 0:00:00 (xfr#29, ir-chk=1249/2436)
media/albums/1/14/thumb_2012-07-28 20.47.49.jpg
7.13K 100% 25.98kB/s 0:00:00 (xfr#30, ir-chk=1248/2436)
media/albums/1/14/thumb_2012-07-28 20.47.59.jpg
6.81K 100% 24.82kB/s 0:00:00 (xfr#31, ir-chk=1247/2436)
media/albums/1/14/thumb_2012-07-28 20.48.06.jpg
7.33K 100% 26.72kB/s 0:00:00 (xfr#32, ir-chk=1246/2436)
media/albums/1/2/
media/albums/1/2/1024_2012-05-03 21.49.27.jpg
56.56K 100% 197.97kB/s 0:00:00 (xfr#33, ir-chk=1245/2436)
media/albums/1/2/1024_2012-05-03 22.37.00.jpg
53.89K 100% 167.60kB/s 0:00:00 (xfr#34, ir-chk=1244/2436)
media/albums/1/2/2012-05-03 21.49.27.jpg
56.56K 100% 173.15kB/s 0:00:00 (xfr#35, ir-chk=1243/2436)
media/albums/1/2/2012-05-03 22.37.00.jpg
53.89K 100% 158.99kB/s 0:00:00 (xfr#36, ir-chk=1242/2436)
media/albums/1/2/2012-05-03 22.53.39.jpg
60.56K 100% 169.46kB/s 0:00:00 (xfr#37, ir-chk=1241/2436)
media/albums/1/2/thumb_2012-05-03 21.49.27.jpg
2.44K 100% 6.80kB/s 0:00:00 (xfr#38, ir-chk=1240/2436)
media/albums/1/2/thumb_2012-05-03 22.37.00.jpg
2.55K 100% 7.10kB/s 0:00:00 (xfr#39, ir-chk=1239/2436)
media/albums/1/2/thumb_2012-05-03 22.53.39.jpg
2.62K 100% 7.31kB/s 0:00:00 (xfr#40, ir-chk=1238/2436)
media/albums/1/23/
media/albums/1/23/2012-08-09-224554_1366x768_scrot.png
152.05K 100% 370.28kB/s 0:00:00 (xfr#41, ir-chk=1237/2436)
media/albums/1/23/2012-08-29-170808_1366x768_scrot.png
162.87K 100% 363.13kB/s 0:00:00 (xfr#42, ir-chk=1236/2436)
media/albums/1/23/2012-09-02-014215_1366x768_scrot.png
155.44K 100% 316.91kB/s 0:00:00 (xfr#43, ir-chk=1235/2436)
media/albums/1/23/2012-09-02-131516_1366x768_scrot.png
147.72K 100% 275.30kB/s 0:00:00 (xfr#44, ir-chk=1234/2436)
media/albums/1/23/2012-09-02-131523_1366x768_scrot.png
259.65K 100% 417.74kB/s 0:00:00 (xfr#45, ir-chk=1233/2436)
media/albums/1/23/2012-09-08-231233_1366x768_scrot.png
171.33K 100% 260.20kB/s 0:00:00 (xfr#46, ir-chk=1232/2436)
O arquivo de log completo do backup anterior (que foi executado com o mesmo script) pode ser encontrado no link
Exemplo curto
o comando que é executado:
rsync -rvLtShP --link-dest=/backupdrive/2015-10-22/media -e ssh [email protected]:/home/modelbrouw/django/production/media /backupdrive/2015-10-24
No destino de backup (2015-10-24), esperaria um link físico de /backupdrive/2015-10-24/media/albums/1/1/1024_chameleon.jpg
para /backupdrive/2015-10-21/media/albums/1/1/1024_chameleon.jpg
... e enquanto eu estou escrevendo isso, eu provavelmente tenho que adicionar o media
ao alvo. Eu tentarei isso primeiro agora.
A barra final + a parte ausente do caminho me mordeu, digitando o pequeno exemplo ajudou.
A solução é que a barra final deve ser adicionada ao $SOURCE
e media
precisa ser adicionado ao eventual $TARGET
.