Skip to content
Snippets Groups Projects
Unverified Commit 6f9be052 authored by BITARD Michaël's avatar BITARD Michaël Committed by GitHub
Browse files

feat(infra): les sauvegardes fichiers et bdd sont sur une infrastructure...

feat(infra): les sauvegardes fichiers et bdd sont sur une infrastructure différente de Camino (#484)
parent 52d43980
No related branches found
No related tags found
No related merge requests found
$ANSIBLE_VAULT;1.2;AES256;prod
33353432353539303933653235343966373364303530313635613331323337363963313530353564
6165396231666664316531643861613036323964323937640a366164373466623664376462303238
64303731336265646436346330653834626266303233366534363532623737323634316433373464
3962316134666539390a656463353364626264646663386637386435353935303530323335393165
32316437353635613266663330303638666263383761343639653533353436346431383033613537
33343738386638386139376162373931643538393563373038663332343135333565313261373633
63373431386635666665623537343539343132663636623630623164323436376536376363356534
32316234313035643861326564623761353334393139383430616162326531373865326337366334
37343037653739353432616266613062356665346433363635366535396461373939666132386234
65313032383938633166656433663734646531303039383532313862323134633663343532303531
62353832663264376165643432306133316537363537383239666130313166393832643539383137
32313639626139303638646535663464323431323331643931326461643234373164373432323632
39396636616333303537363264643237623338613938303961363035393332636436316361303364
63303461653439613339386131353161613664363235306530366538303438306664353262336636
38333434323662343762666539326239383936383635653135376466656163616330393138393336
62353461336265363562303665373730336463376363396362306638313661313464306666663937
63376265633235306136643631623931333839636338363664366337656561626332663034353730
32333033643563376138613436333636623435643865326331666236666233333633646537303062
34323137353635336237373063616435613362353439336565613164386362333737303335663461
38636234666332333332316130393565363136353765313936353134666161303437393339353334
65373330366234393530313739653135616461336266303831393332366438343964343832613733
35663163396538313665623932316537656461633036646564393465353938363838366633646162
32373235333236353164393262316261366261313937313739343630623839356661666634643434
36376436316363323436636530313339656633653566653037656435653162353032613736303134
61646438326265353365626339623065396337383765313531356662323861333763316232653931
35366361366639353730386432373366636466666339303464333236376238323763613961626431
63363337623335636161636432303665353734636330373535303136363361323136613634656162
39633238313663613136313331333362306537666565383562616536666564636637666139393239
36326435343465643835626165373663376564316239626262623332353231303062363432643266
30353262373838393037376336376334636430313536613734393039623735336134363138386530
34376663326362363162306663326331343238323362663532643435326331623564663134653039
66663735396637653732373430383635353439323063316164363930356632363666386465323162
63653132373264343264313531646266366131643163356338666665656633623430656565646564
38613239363566633866626431373464633638323861396138613135353262616233613264343736
35356430623134396439643738343239653733663130663764336364663536363836643235366165
66363763623663623836393836343161383539393432373730323961663639336466656461396630
30613337373839643438373862303838633036373535316531366333356532393037343339646330
63656635373234333666656663326238343235333833613738336564386463343132623734336463
63316632306138376136343462316437613835303636393964386435623364323962323661343038
37363562636536366261343963666333353138633165366132376130643133396364373662323862
3137
30306636646537366236376436323433366462363737336439343562633135326433383232373532
3962363130383136336565303037623839653538623237370a303066613230646462663334616433
32393339653432653533316664623265613464613634646632656331656266666637376362633362
3835316163396365340a343034656630636133373837633037303134653964356633306230373262
62626436383763343763306133326262626534396664303062366666303135326433363036316663
62663736636135313135313366343563353731323538353635356331643232333739396561343733
38346466666630633037373233316536386635333165383562616539613833626164346632346635
33653862613439646335636139386661663132336335373637646364653135666338303239366337
63633436623733643637653065646234626235643566376464313864316239363961353961356134
35306166643730333333393761616232666635363663646437313636636662326563646533323564
64353632653165636563306362656336333139626332376539623363393138383432323633386664
31386638373835333266666362316639313437636565333038626539373130653866636363663939
36636565616135653533383630303661363334343539396663353132343431306237326336303462
39393632633339633437383131313662633832613236303563333566613131623764393433376130
63303139313730626632386264663561616433663631363465396634393236626638396135363935
62353266646664633932346534383434653063646434306430323533313935376564353436663265
63323739663433376233393865303566383264666330326435333339383532663632303466383832
34353737316532643763313231393638326138616531613935653438646630653235646462656236
31386566646435623261316334656563656264383463303238303339393231376164373863643731
62373839336335353338613231363363333937306238336138323739376230353863313637316364
61323138343865356339373062646365633364306133656132633266343033373131343761613032
31313065366361373636376262396563643562383231626264323331353763383238356339396532
64343739383937353764333730373361313862386437333638396465633331643265363035353763
35343934396534393636313230613233663564663232356165623166336534313733356534356430
32353563313566316435666632306530376539373064633137393761336530313832653632623531
39343338383237383962356534333766613531626366376136336231353363343534323830313132
36623137333762303066653930633231383731626463353736303762376263653732313066393362
37656661336533376334386635353235366164633434306637326439646235303938366565356138
33663263366336393337626236663738313665353332303965363762343261623335633863343633
33373864343038326639663861383831663365626636383739373165663430366635353635666563
37333763336238316135356163346633633930616633656132363437343737323534643661343038
31343036356537306564383265333238396535626634336634626632666439333662623135303265
35346132366634356236373033383636376232396135376465363235353530346638373934633835
36366533353661623632323337303032366566343739393066623064306436613730373835666561
35316162326430356233613436663963663261316132393937366236303432346638653964336161
37336363346539383439303839356266333036656633373734396533303362363432613864333764
65343532356437343934663765333465663965363537633033326132363066646465666138663764
34643136613639353837393531613236346465383230393633653134353331393531633739363566
65363366383137376633653865373562623535653563366339396535626332306562376538326130
37653762353631313761653866336338343238386637653630633539376238623536636139316663
65336238336131333031396633366362616138663636323331343132653531396436313963363236
66376564643464623961613739616234363561306530316666366465323235666336303761663638
65626261316633366234306132313132383630356435643238663761383966303163303838353934
62323539366663316464306562386238646339333066633264653438646561663062613837633838
64383739643037326131616239333232393437343737316666626365643335343933383564376231
30316664386265326331316637336239626430383432626463396235653737306363353938336135
30353938336663393261376638346137353337616265663861613730366461306232383933613232
62656530353161363737
---
- name: Ajoute les variables d'environnement
ansible.builtin.template:
src: restic_data
dest: /srv/scripts/
mode: u=rwx,g=rx,o=r
owner: git
group: users
backup: yes
become: True
- name: Ajoute le script de backup
ansible.builtin.template:
src: backup
......
#!/bin/bash
set eufo -pipefail
source /srv/scripts/restic_data
if [ "$(id -u)" != "{{git_user_uid}}" ]; then
echo "This script must be run as git" 1>&2
exit 1
......@@ -9,42 +11,10 @@ fi
# sauvegarde la base de donnees
rm -rf /srv/backups/camino.sql
docker exec camino_api_db pg_dump --clean --if-exists --format=c --no-owner --no-privileges --dbname=camino > /srv/backups/camino.sql
chown git:users /srv/backups/camino.sql
# sauvegarde les fichiers
rm -rf /srv/backups/files/*
docker cp camino_api_app:/packages/api/files/. /srv/backups/files/
chown git:users -R /srv/backups/files
# cree un fichier d'archive
# cree une archive a partir du dossier `files` et du fichier `camino.sql`
FILE_SUFFIX=camino.tar.gz
FILE_PATH=/srv/backups/`date +%Y%m%d"_"%H%M%S`-$FILE_SUFFIX
FTP_URL="ftp://{{ ftp_user }}:{{ ftp_password }}@{{ ftp_host }}/"
echo $FILE_PATH
cd /srv/backups
tar -zcvf $FILE_PATH files/* camino.sql
cd -
chown git:users /srv/backups/*.tar.gz
# Upload le fichier vers le ftp
curl -aT $FILE_PATH $FTP_URL
# Renome le fichier et écrase l’ancien backup
mv $FILE_PATH /srv/backups/$FILE_SUFFIX
# Vérifie qu’on a seulement les 20 derniers backups sur le ftp
if [ $(curl -l $FTP_URL | grep $FILE_SUFFIX | wc -l) -gt 15 ]
then
# Supprime le backup le plus ancien
fileToDelete=$(curl -l $FTP_URL | grep $FILE_SUFFIX | head -n 1)
curl $FTP_URL -Q "DELE $fileToDelete"
fi
rsync --delete -r /srv/www/camino/files/ /srv/backups/files
chown git:users -R /srv/backups/
restic backup /srv/backups/
\ No newline at end of file
export RESTIC_REPOSITORY=s3:https://b3.din.developpement-durable.gouv.fr/Camino
export RESTIC_PASSWORD={{ restic_password }}
export AWS_ACCESS_KEY_ID={{ restic_s3_client_id }}
export AWS_SECRET_ACCESS_KEY={{ restic_s3_client_secret }}
$ANSIBLE_VAULT;1.2;AES256;camino
31633238396362326362393330326361303430633939346630613035303662323635633366326465
3166303438656536643936383934383830613834303838640a653035316366663666626464353833
38656238343561666561663836643566613332373261643730396466333665303832376365376232
3139323436666264310a323162623663623761643339313262363031613039663366373638656633
34616262303662663731373730666636383962353335366432353563373665366361373762346138
38346634313436666632343830326431366132623231626564333562316435393130616430323162
36643332393165353161333832663239376438313165623136353137383235333335303062313461
38343637346539633231643361323538616137323933376239306561343163353237396462376233
3961
......@@ -23,4 +23,9 @@
user: "{{ camino_dev.nom }}"
state: present
key: "{{ camino_dev.ssh }}"
become: True
\ No newline at end of file
become: True
- name: "{{ camino_dev.nom }}: source restic creds"
ansible.builtin.lineinfile:
path: "/home/{{ camino_dev.nom }}/.bashrc"
line: source /srv/scripts/restic_data
when: env == 'prod'
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment