PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Probleme mit cronjob beim Backup



smog_at
05.12.03, 11:06
Hey @all,

Hier mal meine /etc/crontab:


*/15 * * * * test -x /usr/sbin/run-crons && /usr/sbin/run-crons
0 * * * * rm -f /var/spool/cron/lastrun/cron.hourly
0 0 * * * rm -f /var/spool/cron/lastrun/cron.daily
0 0 * * 6 rm -f /var/spool/cron/lastrun/cron.weekly
0 0 1 * * rm -f /var/spool/cron/lastrun/cron.monthly
0 8 * * * emerge sync
0 9 * * * mount /boot && /usr/bin/backup && /umount/boot



Mein Problem ist nun das er den Befehl


0 9 * * * mount /boot && /usr/bin/backup && /umount/boot

nicht startet, auch wenn ich den Befehl "crontab /etc/crontab" ausführe.

Ich habe es auch schon mitfolgendem probiert, jedoch auch ohne Erfolg


0 9 * * * root mount /boot && /usr/bin/backup && /umount/boot
10 9 * * * root /usr/bin/backup

Manuell kann ich /usr/bin/backup ausführen.
Habe für cronjobs dcron installiert


Wäre über jede Hilfe dankbar
MfG smog_at

keeney
05.12.03, 11:26
du startetst den befehl als root? nur der hat normalerweise die rechte /boot zu mounten.
gib mount den kompletten pfad mit, als e.g. /bin/mount /boot

und was soll /umount/boot sein? wohl eher /bin/umount /boot, oder? ;)

du kannst auch mal nen blick in deine log's werfen, oder wenn der interene mail-versand funktioniert, die mails vom crond anschaun, die er an root schickt

Cosmo
05.12.03, 11:38
es reicht im Normalfall nicht aus den Befehl ohne Pfad anzugeben
probier doch mal /sbin/mount /boot usw.

smog_at
05.12.03, 11:47
Das mounten funktioniert jetzt zwar mit:


42 11 * * * /bin/mount /boot && /usr/bin/backup && /bin/umount /boot

Jedoch funktioniert das "/usr/bin/backup" nicht, hier mal die Dateien


-rws--x--x 1 root root 94904 Nov 15 18:01 /bin/mount
-rws--x--x 1 root root 54252 Nov 15 18:01 /bin/umount
-rwxr-xr-x 1 root root 44118 Dec 2 15:31 /usr/bin/backup

MfG smog_at

P.S.: Denke das /usr/bin/backup auch dieselben Rechte haben muss wie mount und
umount, oder liege ich da falsch? Wenn JA, wie bekomme ich das "s" in -rws--x--x?

keeney
05.12.03, 11:54
die rechte passen, root sollte den befehlt ausfuehren koennen.
das s ist ein sticky-bit (chmod +s /bla/blubbs) und hist hier unbrauchbar. man chmod ;)

vielleicht koenntest mal das script posten, damit wir sehen, was passieren sollte? ;)

smog_at
05.12.03, 12:33
Ok, das ist nicht wirklich ein Script, ich habe mir eine Backup-routine in C++ geschrieben, und zwar soll das Verzeichnis vor dem Doppelpunkt gesichert werden, die .TAR.GZ-Dateien werden dann in das Verzeichnis /mnt/Disk_Five/Backups/Linux/backup.HOSTNAME.DATUM gesichert.
Wie gesagt wenn ich es mit /usr/bin/backup manuell aufrufe funktionierts.

Hier mal die Konfigurationsdatei /etc/backup.conf:


/mnt/Disk_Five/Backups/Linux:Backup-Directory
/bin:bin
/boot:boot
/home/httpd:website
/etc:etc
/root:root
/sbin:sbin
/var:var

Und hier der C++-Quellcode:


#include "backup.h"

Backup::Backup() {
this->HostName = getenv("HOSTNAME");
this->FileName = "/etc/backup.conf";
getTime();
}

Backup::~Backup() {
}

void Backup::getConfigFile() {
int counter=0;
ifstream iFile(this->FileName.c_str());

if(iFile) {
while(getline(iFile, line)) {
if(line.substr(0,1)!="#" && !line.empty()) {
string _BackupCommand;
string::size_type pos = line.find(":");
string lhs, rhs;
lhs=line.substr(0,pos);
rhs = line.substr(pos+1,string::npos);

if(counter==0)
this->BackupPath = lhs + "/backup." + this->HostName + "." + DatumLog;
else {
// Command: tar -cf - PATH | gzip -9 > DIRECTORY/FILE.tar.gz
this->BackupCommand.push_back("tar -cPf - " + lhs + " | gzip -9 > " + this->BackupPath + "/" + rhs + ".tar.gz");
this->FROM.push_back(lhs);
this->TO.push_back(rhs);
}

users.push_back(make_pair(lhs,rhs));
counter++;
}
}
iFile.close();
}
}

void Backup::putEntrys() {
cout << "-------------------------------------------------------" << endl;
cout << "Backup::putEntrys():" << endl << endl;
for(VECPAIRITER i=users.begin(); i!=users.end(); ++i)
if(i->first==i->second)
cout << "Kommentar: " << i->first << " - " << i->second << endl;
else if(i->first!=i->second)
cout << i->first << " - " << i->second << endl;
cout << "-------------------------------------------------------" << endl << endl;
}

void Backup::getTime() {
char buffer[20];
struct tm *lTime;
time_t Zeit;

time(&Zeit);
lTime = localtime(&Zeit);

sprintf(buffer,"%02d-%02d-%d", lTime->tm_mday, lTime->tm_mon+1, lTime->tm_year+1900);
this->Datum = buffer;
for(int i=0; i<strlen(buffer); i++)
buffer[i] = '\0';

sprintf(buffer,"%02d-%02d-%d", lTime->tm_mon+1, lTime->tm_mday, lTime->tm_year+1900);
this->DatumLog = buffer;
for(int i=0; i<strlen(buffer); i++)
buffer[i] = '\0';

sprintf(buffer,"%02d:%02d:%02d", lTime->tm_hour, lTime->tm_min, lTime->tm_sec);
this->Uhrzeit = buffer;
for(int i=0; i<strlen(buffer); i++)
buffer[i] = '\0';
}

void Backup::executeBackup() {
string CreateCommand = "mkdir -p " + this->BackupPath;

int controlCreate = system(CreateCommand.c_str());

if(controlCreate) {
cerr << "Kann Verzeichnis " << this->BackupPath << " nicht erstellen!" << endl;
}

string BackupLogFile = this->BackupPath + "/backup.log";
string BackupLogHTMLFile = this->BackupPath + "/backup.html";

ofstream LOGFile(BackupLogFile.c_str());
ofstream LOGHTMLFile(BackupLogHTMLFile.c_str());

if(!LOGFile) {
cerr << "Fehler beim Öffnen von " << LOGFile << endl;
exit(1);
}
if(!LOGHTMLFile) {
cerr << "Fehler beim Öffnen von " << LOGHTMLFile << endl;
exit(1);
}

string FontFace = "Verdana, Arial, Helvetica, sans-serif";

LOGHTMLFile << "<html>" << endl;
LOGHTMLFile << " <head>" << endl;
LOGHTMLFile << " <title>Backup Log File from " << this->Datum << "</title>" << endl;
LOGHTMLFile << " <meta http-equiv=\"Content-Type\" content=\"text/html; ";
LOGHTMLFile << "charset=iso8859-1\">" << endl;
LOGHTMLFile << " </head>" << endl << endl;
LOGHTMLFile << " <body bgcolor=\"#0099CC\">" << endl;
LOGHTMLFile << " <h1 align=\"center\"><font color=\"#FFFFFF\" face=\"" << FontFace << "\">";
LOGHTMLFile << "<u>Backup Log</u></font></h1>" << endl;
LOGHTMLFile << " <h2 align=\"center\"><font color=\"#FFFFFF\" face=\"" << FontFace << "\">";
LOGHTMLFile << "Backup was created at " << Datum << " at " << Uhrzeit << "</font></h2>" << endl;
LOGHTMLFile << " <br>" << endl;
LOGHTMLFile << " <p><font size=\"2\" color=\"#FFFFFF\" face=\"" << FontFace << "\">" << endl;

LOGFile << "Backup was created at " << this->Datum << " at " << this->Uhrzeit << endl;
LOGFile << endl << "--------------------------------------------------------------------------------" << endl << endl;
LOGFile << "Creating Directory: " << this->BackupPath << endl;
LOGFile << " Status: ";

if(!controlCreate)
LOGFile << "OK" << endl;
else
LOGFile << "FAILED" << endl;

LOGFile << endl << "--------------------------------------------------------------------------------" << endl << endl;

LOGHTMLFile << "<br><br><hr size=\"1\" color=\"#00CCFF\" noshade><br>" << endl;

string MySQL1 = "mysqldump DB1 -u USER --password='XXXXXXXXX' > /root/cyberfreaks-" + this->DatumLog + ".mysql";
string MySQL2 = "mysqldump DB2 -u USER --password='XXXXXXX' > /root/volksanw-" + this->DatumLog + ".mysql";
system(MySQL1.c_str());
system(MySQL2.c_str());

for(int i=0; i<this->BackupCommand.size(); i++) {
int controlCommand = system(this->BackupCommand[i].c_str());
LOGHTMLFile << " Saving from: " << this->FROM[i] << "<br>" << endl;
LOGHTMLFile << " Saving to: " << this->BackupPath << "/" << this->TO[i] << ".tar.gz" << "<br>" << endl;
LOGHTMLFile << " Status: ";

LOGFile << "Saving from: " << this->FROM[i] << endl;
LOGFile << " Saving to: " << this->BackupPath << "/" << this->TO[i] << ".tar.gz" << endl;

if(this->FROM[i].find("root")) {
LOGFile << " Kommentar: The databases \"DB1\" and \"DB2\" would be saved to root.tar.gz" << endl;
}

LOGFile << " Status: ";

if(!controlCommand) {
LOGFile << "OK" << endl;
LOGHTMLFile << "<font size=\"2\" color=\"#00FF00\"><b><i>OK</i></b></font><br>";
}
else {
LOGFile << "FAILED" << endl;
LOGHTMLFile << "<font size=\"2\" color=\"#FF0000\"><b><i>FAILED</i></b></font><br>";
}

LOGFile << endl << "--------------------------------------------------------------------------------" << endl << endl;
LOGHTMLFile << "<br><br><hr size=\"1\" color=\"#00CCFF\" noshade><br>" << endl;
}

LOGHTMLFile << " </font></p>" << endl;
LOGHTMLFile << " </body>" << endl;
LOGHTMLFile << "</html>" << endl;

LOGFile.close();
LOGHTMLFile.close();
}




MfG smog_at

keeney
05.12.03, 12:38
*fluecht* das ist zu viel fuer mich :)

smog_at
05.12.03, 12:41
Ihr sollt ja auch nicht den Quellcode verstehen, ich brauche ja nur hilfe, warum er das programm nicht ausführt, den manuell funktioniert es ja, wie ich beschrieben habe. Nur das Kommando
24 11 * * * /usr/bin/backup funktioniert nicht

MfG smog_at

keeney
05.12.03, 13:34
ersetz mal

24 11 * * * /usr/bin/backup

durch

24 11 * * * /usr/bin/backup &> /root/cron-log

vielleicht kannst du dadurch was in erfahrung bringen

smog_at
05.12.03, 13:46
Habe das Problem gelöst, und zwar habe ich mir dcron unmerged, und dafür fcron gemerged.

Vielen Dank nochmals an alle
MfG smog_at