Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Ok setting up a cron task for it... if I wanted it to run a 21:00 everyday, would it be:
00 21 * * * root /root/mysqlbackup.sh
I can't remember whether the clock is in 24 hour format...
I modified the code slightly so it doesn't use ftp (because I don't have a ftp server to dump the data to), and added variables that are slightly easier to change, except it is now asking me everytime for a password even though I have added a variable for password. See if you can figure it out (I'm sure it's a noobish error). Here you go anyway:
Code:
#!/bin/sh
#backup directory
cd /var/backup
#date in format yyyy-mm-dd
date=`date -I`
mysqluname="your user"
mysqlpass="your pass"
mysqldb="your database"
echo "Backup: $date" >> backuplog
echo "Dumping MySQL data..." >> backuplog
#dumps database table structures and data into file backup-yyyy-mm-dd.sql
mysqldump -u $mysqluname -p $mysqlpass $mysqldb > backup-$date.sql 2>>backuplog
#check if this file exists and is not empty, as an with mysqldump in the command above
# will result in creating an empty file
if [ -s backup-$date.sql ]
then
echo "MySQL dump successful." >> backuplog
#remove files beginning with backup- which are older than 7 days
find /var/backup -name "backup-*" -mtime +7 -exec rm -v '{}' \;
else
echo "MySQL dump failed." >> backuplog
echo "MySQL dump failed."
fi
echo "" >> backuplog
exit 0
For the email I suppose you could just use sendmail, but I don't really know how to use this I will have a quick look, but I'm guessing all that needs to be done is a simple message (backuplog?) and an attachment (the .sql file). Maybe try compressing the sql file? Would be useful on large databases...
i decided to use mail instead of sendmail because you can specify the email subject using -s flag, with sendmail u'd need to actually include teh necessary headers in the email
i now have two log files, one is the entire log, and the other is the most recent log entry - this file is appended to the entire log and emailed as the message body. while having a second log like this is a little messy, its the only way i can think of doing this
I too have something similar and need some help with. I making a small script for backing up to a directory and burning to a cdrom and I'd like it to keep the backups around for seven days before deleting, who would i use in my script:
I'm a noob when it comes to programming here's my script if someone can help
#!/bin/bash
#
Backup_Dirs="/tempinst" # eg. /etc /usr/local /opt /var /root /boot
Backup_Dest_Dir=/tmp/backup
Backup_Date=`date +%b%d%Y`
Speed=8 # Use best speed for CD-R/RW disks on YOUR system
# Check to see of backup directory exists, if not then create it
if [ ! -d $Backup_Dest_Dir ]; then
{
mkdir $Backup_Dest_Dir;
}
else
{
echo "Backup Directory already exists";
}
fi
# Create tar file with todays Month Day Year prepended for easy identification
tar -cvzf $Backup_Dest_Dir/$Backup_Date.tar.gz $Backup_Dirs > $Backup_Dest_Dir/backup_$Backup_Date.log
echo "Create $Backup_Date.img including log file"
# Create a image that can be written to writeable media
Size=`du -m $Backup_Dest_Dir/$Backup_Date.img | cut -c 1-3`
if [ $Size -lt 680 ];then
{
echo "Size of $Backup_Date.img is $Size MB, OK to Burn";
}
else
{
echo "Size of $Backup_Date.img too Large to burn too CD-R....Maybe time for DvD Burner";
exit1
}
fi
# Burn the CD-RW
echo "Burning back-up to disc."
cdrecord dev=ATAPI:0,1,0 -v -eject fs=64M driveropts=burnproof speed=$Speed -tao $Backup_Dest_Dir/$Backup_Date.img
echo "Successfully backed-up $Backup_Date.img to cd-r/rw"
Would you be interested in writing something similar to this in python? I have never wrote anything in it before and would like to learn, so it seems like a nice project to start on. How good are you at writing in python Jon? And thanks for the tip about using mail! Just changed the sendmail line to mail -s "mysql backup" tom@tomj.sytes.net < /var/backup/backup-$date.sql and it works perfectly!
i've only recently started learning python - i started writing a very basic rss reader which grabs the rss file, downloads it, parses it and outputs some of the data, but i've got a bit bored of that now
i may well write a similar script in python, depends really if i am set any more work for my last week at my internship i'm currently doing (and for which i am writing this script to backup the database backend of my project), or if i have some free time.
i have a python network programming book at home which covers ftp, and i have some knowledge already of reading and writing to files.
I've still got 3 weeks left before I go back to school hehe... starting my computing course in 6th form then, and the school has just purchased visual basic .net .... but I believe we can use c, c++ and other languages, let's hope that I can use something other than vb.net haha
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.