We help IT Professionals succeed at work.
Get Started

Linux backup script

Last Modified: 2013-12-06

I'm trying to automate the backup of key files from a linux server running Fedora 12. I have put together the following commands:


# RT Backup Script

# Move to backup folder
cd /home/administrator/Desktop/RTBackups

# Remove all existing backup folder
rm -rf RT*

# Create new folder
DATE='date +"%d-%m-%y"'
mkdir /home/administrator/Desktop/RTBackups/$FOLDER

# Dump database to folder
mysqldump --opt rt3 -u root --password=passwordhere > /home/administrator/Desktop/RTBackups/$FOLDER/rt3-db-backup

# Copy web files to folder
cp /etc/httpd/conf/httpd.conf /home/administrator/Desktop/RTBackups/$FOLDER

# Copy mail files to folder
cp /etc/hosts /home/administrator/Desktop/RTBackups/$FOLDER
cp /etc/aliases /home/administrator/Desktop/RTBackups/$FOLDER
cp /etc/mail/access /home/administrator/Desktop/RTBackups/$FOLDER
cp /etc/mail/local-host-names /home/administrator/Desktop/RTBackups/$FOLDER
cp /etc/mail/sendmail.mc /home/administrator/Desktop/RTBackups/$FOLDER

# Copy RT files to folder
cp /opt/rt3/etc/RT_SiteConfig.pm /home/administrator/Desktop/RTBackups/$FOLDER

# Move ready for backup
cd /home/administrator/Desktop

# Copy backup to SubRes
smbclient // -U backupuser backup -c 'cd Backups/RequestTracker;recurse;prompt NO;mput RTBackups;quit'

Open in new window

Firstly a cannot get the date function to work, I get the following error:
mkdir: cannot create directory `+"%d-%m-%y"': File exists
/home/administrator/Desktop/rtbackupscript.sh: line 17: /home/administrator/Desktop/RTBackups/RTdate +"%d-%m-%y"/rt3-db-backup: No such file or directory

Also I get permission denied on a folder in /opt - I need to su- within the script so that the file can be copied.

The backup needs to be automated so I cannot have it prompt for passwords.

The smbclient command also does not work:
Connection to failed (Error NT_STATUS_UNSUCCESSFUL)

All smb ports are open on the firewall.

COuld anyone help please?

Watch Question
This problem has been solved!
Unlock 3 Answers and 10 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE