This script backup directories /etc/astra and file /usr/bin/astra to email.
SendEmail is a lightweight, completely command line-based SMTP email delivery program
yum install sendemail
sudo apt-get install sendemail
Create a script:
#!/bin/bash MAILTO="firstname.lastname@example.org" FROM="email@example.com" SMTPSERVER="smtp.gmail.com:587" SMTPLOGIN="my-email" SMTPPASS="password" NOW=$(date +%Y%m%d) BACKUP="/tmp/astra-$NOW.tar.gz" tar -zcf $BACKUP /etc/astra /usr/bin/astra SUBJ="$FROM backup" BODY="The backup was successfully completed. The backup files are attached in this email" /usr/bin/sendEmail \ -f $FROM -t $MAILTO \ -o message-charset=utf-8 \ -u $SUBJ -m $BODY -a $BACKUP \ -s $SMTPSERVER -o tls=yes -xu $SMTPLOGIN -xp $SMTPPASS rm -f $BACKUP
Save this script as backup.sh in the directory /opt
If you have 2 factor auth enabled, you need to create an “application password”, then use that instead of your normal password.
Configure cron (Linux task scheduler)
Open the editor with the command
sudo crontab -u root -e
And in the opened file add a line:
40 2 * * * sh /opt/backup.sh > /dev/null
Do not forget to put Enter at the end of the line (to line break!)
Save the file. Now at 2 hours 40 minutes (at night) you will have a backup of Astra in your e-mail