Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

I need a backup script

rahulksrahulks Member

need a backup script for my ubuntu vps which backups all sql databases including users, directories /var/www/ /etc/apache2/ /root/

and the backup should be send as an email attachment

Does anybody know some kind of script which can do this ?

Comments

  • nunimnunim Member
    edited April 2014

    There isn't going to be a script that meets your exact needs, however Bash is quite simple and you should be able to cobble one together.

    Sending a backup as an email attachment is a very poor idea, you should be uploading it offsite via SCP or rsync ideally.

    I'll get you started:

    mkdir /home/backup/
    cp -rf /var/www/ /home/backup/www/
    cp -rf /etc/apache2 /home/backup/apache2/
    cp -rf /root/ /home/backup/root/
    tar -czf /home/files_backup.tar.gz /home/backup/
    rm -rf /home/backup/

    Now you just need to dump your databases and send the files offsite.

  • XSXXSX Member, Host Rep
    edited April 2014
    #!/bin/bash
    mkdir /backup
    tar zcf /backup/backup_$(date +"%Y%m%d").tar.gz  /var/www/ /etc/apache2/ /root/
    mysqldump -uYOUUSER -pYOUPASSWORD YOUDATABASE | gzip -9 - > /backup/db_$(date +"%Y%m%d").sql.gz)
    
  • mikhomikho Member

    Dump mysql and tar evry directory you need backuped and use something line ssmtp ( http://www.lowendguide.com/3/email/low-memory-usage-smtp-send-only/) to send the file.

    Make sure that the total size of the email isn't larger then what your mail provider can accept.

Sign In or Register to comment.