How to avoid corrupted SD card ?

Hi,

I am using Sdfat lib for datalogging on SD card with SPI.

I write a record every 1second, about 29Mo/day.
For each record, I open the file, write and then close the file.

about everyday a new file is started.

I works relatively well. But after a while ( 1 month this time) something get corrupted
and the program stalls or runs much more slowly, and the card structure has to be cleaned
from some error.

What would be a good strategy to have a more robust system, that could run for more than one year
(12 Go of data) without any problem ?

Thanks

Edit : The card are connected to an Arduino Due. Everything is with 3.3V.
Same problem occured with an Atmega328, also in 3.3V.

What would be a good strategy to have a more robust system, that could run for more than one year
(12 Go of data) without any problem ?

Do you have a 12Gig card?

But after a while ( 1 month this time) something get corrupted
and the program stalls or runs much more slowly, and the card structure has to be cleaned
from some error.

The code you didn't post? How do you "clean the card structure"? Ajax and a scrub brush and a bucket of warm water?

PaulS:
Do you have a 12Gig card?

No, a 16 Gig card, but one year of data is 12 gigs.

How do you "clean the card structure"? Ajax and a scrub brush and a bucket of warm water?

This could be some way to do it, but I have not tried. I simply put the card in the lector of the MacBook Pro, and fix the structure with the diskUtility tool.

The code you didn't post?

No, I did not think it was necessary. It may distract you from the real question which is wether there is a general strategy to avoid these kind of corruption.

To satisfy your curiosity, I have nevertheless put below the code that concerns the SD card. Hope it is useful.

#include <SdFat.h>

void loop() {
long sec=0;
String file=String();
// acquisition des donnees
// testRTC ();
update_baro();
update_env();
outSD();
outserial();
// affichage ecran
lcdbar();
}

void outSD(void) {
// sauvegarde carte SD simple
// ouvreSDFX(fileName);
// ouvreSDF();
digitalWrite(ledSD,HIGH);
ouvreSDFX(fileName);
ecritureSD();
fermeSDF();
digitalWrite(ledSD,LOW);
}

void ecritureSD() {
// sauvegarde carte SD : ecritures seules
outbaro();
SDF.print(baraux);
// SDF.print(caux0);
SDF.print("\r\n");
}

void ouvreSDFX(char filena[]) {
if (!SDF.open(filena, O_RDWR | O_CREAT | O_AT_END)) {
sd.errorHalt();
Serial.println(F("opf failed"));
}
// clock : ajustement des dates de creation du fichier
now = rtc.now();
if (!SDF.timestamp(T_CREATE, (uint16_t)now.year(), (uint8_t)now.month(), (uint8_t)now.day(), (uint8_t)now.hour(), (uint8_t)now.minute(), (uint8_t)now.second())) {
Serial.println(F("set create time failed"));
}
if (!SDF.timestamp(T_WRITE, (uint16_t)now.year(), (uint8_t)now.month(), (uint8_t)now.day(), (uint8_t)now.hour(), (uint8_t)now.minute(), (uint8_t)now.second())) {
Serial.println(F("set write time failed"));
}
// set access date
if (!SDF.timestamp(T_ACCESS, (uint16_t)now.year(), (uint8_t)now.month(), (uint8_t)now.day(), (uint8_t)now.hour(), (uint8_t)now.minute(), (uint8_t)now.second())) {
Serial.println(F("set access time failed"));
}
// digitalWrite(pinSD,HIGH);
}

void fermeSDF(void) {
SDF.close();
// digitalWrite(pinSD,LOW);
}