Chorke Academia Backup: Difference between revisions

From Chorke Wiki
Jump to navigation Jump to search
Line 29: Line 29:
BACKUP_DATE_TIME="\$(date +'%Y%m%d-T%H%M')-Z\$(date +'%z'|tr '+-' 'PM')"
BACKUP_DATE_TIME="\$(date +'%Y%m%d-T%H%M')-Z\$(date +'%z'|tr '+-' 'PM')"


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


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


# backup chorke nginx
# backup certificates
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 chorke certificates
ARCHIVE_TARGET=\${HOME}/app_backup/chorke-certificates_\${BACKUP_PRO}-\${BACKUP_ENV}-\${BACKUP_DATE_TIME}.tar.gz
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}
cd /var/chorke/academia/chorke-policy/\${BACKUP_ENV}-\${BACKUP_PRO}
tar -czvf \${ARCHIVE_TARGET} certificates
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
EXE



Revision as of 09:25, 29 June 2024

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 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 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
'

References