Chorke Academia Backup

From Chorke Wiki
Jump to navigation Jump to search

Backup » CSV

ssh [email protected]
mkdir -p ~/rds_backup/

cat  << EXE | bash
BACKUP_PRO='academia'
BACKUP_ENV='production'
BACKUP_DATE_TIME="\$(date +'%Y%m%d-T%H%M')-Z\$(date +'%z'|tr '+-' 'PM')"
cat  << SQL | psql -U postgres chorke_policy
\COPY (\
SELECT \
    status, product_name "product name", ref_code AS "policy number", properties->>'Full Name' AS "full name", \
    properties->>'Start Date' AS "effective date", properties->>'End Date' AS "expiry date" \
FROM policy WHERE status IN ('Not in Effect', 'In Effect') ORDER BY id DESC) \
TO '\${HOME}/rds_backup/chorke-policy-status_\${BACKUP_PRO}-\${BACKUP_ENV}-\${BACKUP_DATE_TIME}.csv' DELIMITER ',' CSV HEADER;
SQL
EXE

mkdir -p ~/Documents/backup-playground/
cd       ~/Documents/backup-playground/
scp [email protected]:~/rds_backup/*.csv .

Backup » Databases

ssh [email protected] 
mkdir -p ~/rds_backup/

cat  << EXE | bash
BACKUP_PRO='academia'
BACKUP_ENV='production'
BACKUP_DATE_TIME="\$(date +'%Y%m%d-T%H%M')-Z\$(date +'%z'|tr '+-' 'PM')"
for d in keycloak quote policy;do
    pg_dump -U postgres "chorke_\${d}"\
     | gzip > "${HOME}/rds_backup/chorke-\${d}_\${BACKUP_PRO}-\${BACKUP_ENV}-\${BACKUP_DATE_TIME}.sql.gz";
done
EXE

mkdir -p ~/Documents/backup-playground/
cd       ~/Documents/backup-playground/
scp [email protected]:~/rds_backup/*.sql.gz .

Backup » Services

ssh [email protected]
mkdir -p ~/app_backup/

cat  << EXE | bash
BACKUP_PRO='academia'
BACKUP_ENV='production'
BACKUP_DATE_TIME="\$(date +'%Y%m%d-T%H%M')-Z\$(date +'%z'|tr '+-' 'PM')"

# backup unsymmetrical
for d in keycloak;do
    ARCHIVE_TARGET=\${HOME}/app_backup/\${d}_\${BACKUP_PRO}-\${BACKUP_ENV}-\${BACKUP_DATE_TIME}.tar.gz
    CURRENT_DEPLOY=/var/chorke/academia/\${d}/\${BACKUP_ENV}-\${BACKUP_PRO}/current
    RELEASE_STORES=\$(dirname  "\$(readlink -f \${CURRENT_DEPLOY})")
    RELEASE_DEPLOY=\$(basename "\$(readlink -f \${CURRENT_DEPLOY})")
    cd \${RELEASE_STORES};tar -czvf \${ARCHIVE_TARGET} \${RELEASE_DEPLOY}
done

# backup symmetrical
for d in product quote policy portal d2c verify;do
    ARCHIVE_TARGET=\${HOME}/app_backup/chorke-\${d}_\${BACKUP_PRO}-\${BACKUP_ENV}-\${BACKUP_DATE_TIME}.tar.gz
    CURRENT_DEPLOY=/var/chorke/academia/chorke-\${d}/\${BACKUP_ENV}-\${BACKUP_PRO}/current
    RELEASE_STORES=\$(dirname  "\$(readlink -f \${CURRENT_DEPLOY})")
    RELEASE_DEPLOY=\$(basename "\$(readlink -f \${CURRENT_DEPLOY})")

    # exclude unnecessary files and compress
    printf -v ARCHIVE_EXCLUDE '%s=%s/node_modules' '--exclude' \${RELEASE_DEPLOY}
    cd \${RELEASE_STORES};tar \${ARCHIVE_EXCLUDE} -czvf \${ARCHIVE_TARGET} \${RELEASE_DEPLOY}
done

# backup certificates
ARCHIVE_TARGET=\${HOME}/app_backup/chorke-certificates_\${BACKUP_PRO}-\${BACKUP_ENV}-\${BACKUP_DATE_TIME}.tar.gz
cd /var/chorke/academia/chorke-policy/\${BACKUP_ENV}-\${BACKUP_PRO}
tar -czvf \${ARCHIVE_TARGET} certificates

# backup nginx
ARCHIVE_TARGET=\${HOME}/app_backup/chorke-nginx_\${BACKUP_PRO}-\${BACKUP_ENV}-\${BACKUP_DATE_TIME}.tar.gz
cd /etc/nginx;tar -czvf \${ARCHIVE_TARGET} sites-enabled
EXE

mkdir -p ~/Documents/backup-playground/
cd       ~/Documents/backup-playground/
scp [email protected]:~/app_backup/*.tar.gz .

Backup » Upload

AWS » S3 » Buckets » projects » backups » chorke » academia » production » 20240628-T2023-ZP0800
AWS » S3 » Buckets » projects » backups » chorke » academia » release    » 20240628-T2023-ZP0800
AWS » S3 » Buckets » projects » backups » chorke » academia » develop    » 20240628-T2023-ZP0800

Backup » Extract

tar -tzvf chorke-nginx_academia-production-20240628-T2023-ZP0800.tar.gz
tar -xzvf chorke-nginx_academia-production-20240628-T2023-ZP0800.tar.gz

tar -xzvf chorke-nginx_academia-production-20240628-T2023-ZP0800.tar.gz\
 -C chorke-nginx-academia-production

DateTime » Format

echo "$(date +'%Y%m%d-T%H%M')-Z$(date +'%z'|tr '+-' 'PM')"
:'
20240628-T2023-ZP0800
├─ 20240628
│  ├─ 2024 « %Y
│  ├─ 06   « m%
│  └─ 28   « %d
├─ -T2023
│  ├─ -    « -
│  ├─ T    « Time
│  ├─ 20   « %H
│  └─ 23   « %M
└─ -ZP0800
   ├─ -    « -
   ├─ Z    « Zone
   ├─ P    « {P: Plus (+), M:Minus (-)}
   └─ 0800 « Time Offset
'

Playground

  scp -r   [email protected]:~/Documents/docker-playground/ .
rsync -avz [email protected]:~/Documents/docker-playground/ .

References