Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
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.
# 6. Remove the file that it was sent over email. Would not be dangerous to call rm and delete also other files?
#rm -f $COMPRESSEDFILENAME
I am scared that the $COMPRESSEDFILENAME might get some "funny" value and destroy my file system. I am running these scripts as root user and I still do not feel safe.
In order to gain confidence, you could add a line to report $COMPRESSEDFILENAME so you can see if it is correct:
Code:
echo $COMPRESSEDFILENAME
If you are running the script yourself at the command line, that will print $COMPRESSEDFILENAME. If you are running it by cron, I think it will email it to the cron user, which is root in your case.
By the way, why are you running it as root? If you own the files as a regular user, you should be able to run the script in that user's crontab. That would be safer. As a general security practice, I would only run a script as root if it really needed root privileges, and I would make sure no other user can modify or run the script.
If it were me, I would cut-short this effort to "homebrew" yet-another backup tool, and grab one of the great-many fully featured tools that are already out there: open-source or commercial. A backup process, in order to be truly effective, must run constantly throughout the day ... must secure the backup files where only the backup daemons can get to them ... and must be truly bulletproof. I've seen a lot of cases where the client kit-bashed something together which utterly let them down when they actually tried to use it. (And another case where an intruder was tapping into the backup datasets as a way of completely circumventing the security of the stored data!)
Hi all,
I have decided over the weekend to finish the script and not allow my self to go for external programs for a simple task like that.
Currently the code runs but after finishing with the zipped file, the script stays "hanging" (no command prompt returnd back nor I receive any email). Any ideas what might be causing this?
Regards
Alex
Code:
#!/bin/bash
# Description. This script is for compressing my thesis folder and then sending it over email. Once the email is succesfully sent remove the compressed file.
SCRIPTNAME=$(basename ${0})
MAILADDRESS="HideForNow"
THESISFOLDER="HideForNow"
TEMPSAVEFOLDER="HideForNow"
TIMESTAMP=$(date +%F)
COMPRESSEDFILENAME="$TEMPSAVEFOLDER"myname_thesis"$TIMESTAMP".tar.bz2
doEmail() { case "$1" in
4) REASON="Failed To compress File. $(echo $SCRIPTNAME)"
SUBJECT="Thesis Backup Script failed"
;;
5) REASON="Failed to send email $(date). $(echo $SCRIPTNAME)"
SUBJECT="Thesis Backup Script failed "
;;
6) REASON="Failed to remove file$(date). $(echo $SCRIPTNAME)"
SUBJECT="Thesis Backup Script failed "
;;
7) REASON="Backup Script Finished. $(echo $SCRIPTNAME)"
SUBJECT="Thesis Backup Completed"
;;
*) echo "Please don't do that, Dave..." >/dev/stderr;;
esac; echo "${REASON}" | mail -r $MAILADDRESS -s "${SUBJECT}" $MAILADDRESS; }
# 4. Compress Email
tar -jcvf "$COMPRESSEDFILENAME" "$THESISFOLDER"
if [[ $? -ne 0 ]]
then
doEmail 4; exit 1; # Compressing the file failed
fi
#5. Send the File by email.
mail -r $MAILADDRESS -s "Thesis Backup $TIMESTAMP" -a $COMPRESSEDFILENAME $MAILADDRESS;
if [[ $? -ne 0 ]]
then
doEmail 5; exit 1; # Sending email failed
fi
# 6. Remove the file that it was sent over email. Would not be dangerous to call rm and delete also other files?
#rm -f $COMPRESSEDFILENAME
# 7. Everything went as planned. Bye By
doEmail 7; exit 0; # Exit 0 when normally returns
Is there a specific reason to be using email to transfer the backup?
I can think of two specific reasons:
Method of getting file from Computer A to Computer B
Method of storing file on mail server (like on gmail account)
#1 would be a lot more efficient and easier with rsync or scp and #2 would be a lot more practical with a online cloud backup.
I know a few people who email files to themselves to back it up and it's generally because they don't know any better way.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.