Auto-Backup Amazon S3 Daq
recently backups security critical jIH. V-server (website host) experiment law' 'ej configuration ruin laH. fresh clean system Daq work feeling love - "reinstall-happy". existing configurations files manual backup annoying. automatic backups natural? small script write, Git Daq publish.
installation / execution simple.
Step 1: S3 bucket create
Amazon Web Services account already set up assume. pagh vaj: aws.amazon.com
S3 section Daq jaH (search S3 type), Create bucket click, name 'ej region bucket vaD.
ACLs disable 'ej all public access disable (miss vaj nuq qaS: rudrasarkar.medium.com - how-i-hacked-92k-users).
versioning disabled (file versioning neH vaj choice SoH; jIH latest version neH) 'ej encryption disabled (with without encryption choice SoH).
next step: username choose, access type access key - programmatic access.
Permissions step: "Attach existing policies directly" 'ej "AmazonS3FullAccess". Next: Tags click (nothing do).
next step: Access key ID 'ej Secret access key values copy. keys secret - share Qo'. key combination ghaj vay' files access laH.
Voilà, step one done. Amazon S3 bucket ghaj (API via access).
Step 2: credentials set up
S3 authenticate cha' ways.
Way one: credentials file create. ~/.aws/credentials file contents:
[default]
aws_access_key_id = <zugriffsschlüsselid>
aws_secret_access_key = <geheimerzugrifsschlüssel>
~/.aws/config file contents:
[default]
region = <region>
(bucket region qaw vaj web management console Daq legh)
Python script S3 authenticate laH.
Way two: script Daq credentials direct enter (variables aws_access_key_id, aws_secret_access_key, region_name). recommend pagh - credentials unprotected visible (script access ghaj Hoch vaD).
Step 3: my.cnf create
database je backup vaj database credentials register poQ. my.cnf via Dun.
shell Daq commands type:
m=`which mysqld`
$m --verbose --help | grep -A 1 "Default options"
my.cnf path (/etc/my.cnf) tlhap
poSmoH 'ej file end Daq chel
[client]
user=<deinmysqlrootusername>
password=<deinmysqlrootpasswort>
That's it. user MySQL shell Daq username/password pagh login laH.
alternatively credentials script Daq direct enter. disadvantages above :-)
Step 4: script configure
script server Daq upload 'ej edit. variables edit poQ:
- entities = folders pagh files array (subfolders je!) backup
- bucketname = S3 bucket name
- db_path = file checksums store database path
- aws_access_key_id = AWS access key. config file step 2 vaj None
- aws_secret_access_key = AWS secret key. config file step 2 vaj None
- region_name = bucket region name. config file step 2 vaj None
- backup_databases = True (Hoch databases backup) pagh False
- mysql_username = MySQL username. config file step 3 vaj None
- mysql_password = MySQL password. config file step 2 vaj None
- mysql_tmp_dump_file = temporary database dump naDev create. folder writable poQ.
- s3_mysql_dump_path = database dump path S3 bucket Daq
Step 5: dependencies load
S3 upload vaD script Boto lo'.
TinyDB je file checksums small database Daq store (path variable db_path Daq).
dependencies install: shell Daq command:
pip3 install -r requirements.txt
packages Hoch install.
Step 6: Run it!
test run command enter:
python3 s3backup.py
script finish vaj S3 bucket legh. hierarchy same server rap 1:1 copy files/folders/subfolders (entities variable Daq specified).
Step 7 (Extra): cronjob automate
cronjob via automate easy.
Python3 installation nuqDaq find:
which python3
/usr/bin/python3 output.
type
crontab -e
'ej naDev
0 0 */5 * * <Pfad-zu-Python3> <Pfad-zum-backup-skript.py>
Ctrl+X (close) 'ej Y (yes, save!). 5 days Hoch 24:00 backup automatically execute.