평소에 백업을 중요시 생각하고 항상 신경쓰고 있는 대목이기는 하다.
https://soonj.net/blog/370432
하지만 이딴 황당한 경험까지 하고 나니 그 중요성을 새삼 느끼게된다.
생각난김에 개인적으로 백업하고 있는 방법들을 소개해보겠다.
알고보면 인터넷에 널려있는 자료를 재방송하는 것일 수도 있다. 하지만... 그래도 셋트로..
그 첫번째는 데이터베이스, 물론 mysql이다.
sudo vi /etc/cron.daily/dbbackup.sh
################################################################################### # User with SELECT, SHOW VIEW, EVENT, and TRIGGER, or... root # Archive path # Archive filename # Archives older than this will be deleted # Change working directory # Get all of the databases # Skip ones we don't want to back up # Use Nice to dump the database done # Use Nice to create a tar compressed with bzip2 # Remove the SQL files # Remove old archive files |
퍼미션을 맞춰야 실행이 가능하다.
sudo chmod 755 /etc/cron.daily/dbbackup.sh
sudo /etc/cron.daily/dbbackup.sh
실행하고 해당 폴더에 보면 데이터베이스가 날짜와 시간을 화일명으로 tbz2로 압축되어 저장된다.
DB_2023-04-25_14-59-44.tbz2 DB_2023-04-26_03-16-56.tbz2 DB_2023-04-27_03-21-04.tbz2 |
해당 압축을 풀때는
tar -jxf DB_2023-04-27_03-21-04.tbz2
/etc/cron.weekly와 /etc/cron.monthly에도 하나씩 만들어주면 더 좋다.
물론 이때 수정은 필수..