ctucx.git: ansible-configs

My personal ansible roles and playbooks [deprecated in favor of nixos]

1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
27 
28 
29 
30 
31 
32 
33 
34 
35 
36 
37 
38 
39 
40 
41 
42 
43 
#!/usr/bin/env sh

echo "Last run: $(date -R)" > /root/backup.last-run 

for backupTarget in desastro lollo
do
  echo "Backing up to: $backupTarget"  >> /root/backup.last-run
  echo "Status:" >> /root/backup.last-run
  #backup services
  for service in pleroma radicale synapse git maddy oeffisearch
  do
    sudo -u $service restic init --password-file /var/lib/$service/restic-password --repo rest:https://restic:$(cat /var/lib/restic-password-$backupTarget)@restic.$backupTarget.ctu.cx/$(hostname)-$service
    sudo -u $service restic backup --password-file /var/lib/$service/restic-password --repo rest:https://restic:$(cat /var/lib/restic-password-$backupTarget)@restic.$backupTarget.ctu.cx/$(hostname)-$service /var/lib/$service
    if [ $? -eq 0 ]; then
    	echo "$service: OK" >> /root/backup.last-run
    else 
    	echo "$service: FAIL" >> /root/backup.last-run
    fi
  done

  #backup websites
  sudo -u leah restic init --password-file /var/lib/websites/restic-password --repo rest:https://restic:$(cat /var/lib/restic-password-$backupTarget)@restic.$backupTarget.ctu.cx/$(hostname)-websites
  sudo -u leah restic backup --password-file /var/lib/websites/restic-password --repo rest:https://restic:$(cat /var/lib/restic-password-$backupTarget)@restic.$backupTarget.ctu.cx/$(hostname)-websites /var/lib/websites --exclude /var/lib/websites/photos.ctu.cx
  if [ $? -eq 0 ]; then
    echo "websites: OK" >> /root/backup.last-run
  else 
    echo "websites: FAIL" >> /root/backup.last-run
  fi

  #backup postgres
  SQLFILE=/var/lib/postgresql/backup/postgres.sql
  sudo -u postgres mkdir /var/lib/postgresql/backup
  sudo -u postgres sh -c "pg_dumpall > $SQLFILE"
  sudo -u postgres restic init --password-file /var/lib/postgresql/restic-password --repo rest:https://restic:$(cat /var/lib/restic-password-$backupTarget)@restic.$backupTarget.ctu.cx/$(hostname)-postgres
  sudo -u postgres restic backup --password-file /var/lib/postgresql/restic-password --repo rest:https://restic:$(cat /var/lib/restic-password-$backupTarget)@restic.$backupTarget.ctu.cx/$(hostname)-postgres /var/lib/postgresql/backup
  if [ $? -eq 0 ]; then
    echo "postgres: OK" >> /root/backup.last-run
  else 
    echo "postgres: FAIL" >> /root/backup.last-run
  fi
  sudo -u postgres rm -rf /var/lib/postgresql/backup
  echo ""  >> /root/backup.last-run 
done