Chorke Academia Backup

From Chorke Wiki
Revision as of 09:16, 29 June 2024 by Shahed (talk | contribs) (Created page with "==Backup » Databases== <syntaxhighlight lang="bash"> 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 "academia_\${d}"\ | gzip > "${HOME}/rds_backup/chorke-\${d}_\${BACKUP_PRO}-\${BACKUP_ENV}-\${BACKUP_DATE_TIME}.sql.gz"; done EXE mkdir -p ~/Documents/backup-pla...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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 "academia_\${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]

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 academia 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 academia 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})")

    # 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 academia 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

# backup academia 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
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
'

References