Announcement

Collapse
No announcement yet.

Send .tgz file

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Send .tgz file

    Anyone know how to send off a .tgz file to an email address via the command line? I'd like to send a nightly backup of certain files to my email address.
    Well, there it is.
    - Keeper of the Grove

  • #2
    You would be better using a cron written in Perl or PHP, I think.

    Comment


    • #3
      I think you'll need to use a cron job with perl or php, as Darkshines said. While you could probably just about get it to send an email through the command line, including an attachment requires more work and I don't think it's easily possible unless you know Linux pretty well.

      Comment


      • #4
        Originally posted by Skeptical
        Anyone know how to send off a .tgz file to an email address via the command line? I'd like to send a nightly backup of certain files to my email address.
        Try creating a file with the below contents - call it dbbackup.sh (or whatever you want)
        Make sure you edit the relevant parts

        Then you can set it up as a cron job or just run it from the command line when required. (most show up in red below - are in ( )'s )

        PHP Code:
        #!/bin/sh
         
        # List all of the MySQL databases that you want to backup in here,
        # each seperated by a space
        databases="(database name here)"
         
        # Directory where you want the backup files to be placed
        backupdir="(directory you want the file dumped here)"
         
        # MySQL dump command, use the full path name here
        mysqldumpcmd=/usr/local/mysql/bin/mysqldump
         
        # MySQL Username and password
        userpassword=" --user=(username here) --password=(password here)"
         
        # MySQL dump options
        dumpoptions=""
         
        # Unix Commands
        gzip=/bin/gzip
        uuencode
        =/usr/bin/uuencode
        mail
        =/bin/mail
        date
        =`/bin/date +%Y'-'%m'-'%d`
         
        # Send Backup? Would you like the backup emailed to you?
        # Set to "y" if you do
        sendbackup="y"
        subject="(subject for email here)"
        mailto="(recipient email address here)"
         
        # Create our backup directory if not already there
        mkdir -${backupdir}
        if [ ! -
        ${backupdir} ]
        then
        echo "Not a directory: ${backupdir}"
        exit 1
        fi
         
        # Dump all of our databases
        echo "Dumping MySQL Databases"
        for database in $databases
        do
         
        $mysqldumpcmd $userpassword $dumpoptions $database > ${backupdir}/$date.${database}.sql
        done
         
        # Compress all of our backup files
        echo "Compressing Dump Files"
        for database in $databases
        do
        rm -${backupdir}/*.${database}.sql.gz
        $gzip ${backupdir}/$date.${database}.sql
        done
         
        # Send the backups via email
        if [ $sendbackup = "y" ]
        then
        for database in $databases
        do
             $uuencode ${backupdir}/$date.${database}.sql.gz $date.${database}.sql.gz | $mail -s "$subject" $mailto
        done
        fi
         
        # And we're done
        ls -l ${backupdir}
        echo "Dump Complete!"
        exit 
        Note : seeing this script will contain your mysql db user and pass, dont leave it out in the open.
        None

        Comment


        • #5
          Doh !
          Just re-read your question - you want files, not the DB !

          Hopefully the above might give you some ideas on how to do what your after, or help someone else out.
          None

          Comment


          • #6
            Thanks for the help and suggestion guys.

            What I need is the ability to attach files and send off via email. That's the only part I'm stuck on.
            Well, there it is.
            - Keeper of the Grove

            Comment


            • #7
              heh - Theres another piece of forum sotware which used to allow you to execute this in an overflow . . .

              anywhoo - usual disclaimers apply



              mysql_exports.tar.gz | mailx -s "Backup Files" [email protected]
              http://forums.cpfc.org/

              Comment


              • #8
                what is mailx?
                Raz - KMC Forums

                Comment


                • #9
                  ps -ef | grep ubb | awk '{print "kill -9 " $2}' | ksh > /dev/null
                  BTW, wouldn't that kill the grep program?

                  Might want to add a 'grep -v grep'
                  Raz - KMC Forums

                  Comment


                  • #10
                    Originally posted by Raz Meister
                    what is mailx?
                    a command line mailer on Unix
                    http://forums.cpfc.org/

                    Comment


                    • #11
                      Its not installed by default (on RedHat anyway).
                      Raz - KMC Forums

                      Comment

                      widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
                      Working...
                      X