Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4546924
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T16:01:24+00:00 2026-05-21T16:01:24+00:00

I have a database and I used to backup daily manually like so mysqldump

  • 0

I have a database and I used to backup daily manually like so

 mysqldump -uroot -ppassword forum > 4.25.2011.sql

However I’ve been doing the above and wanted to use a script besides mysqldumper to do the job.

If 3 existing .sql files exist in the backup directory, how can I delete the oldest one?

So far all I have is:

#!/bin/bash
today = `eval date +%m.%d.%Y` #how do I add this to the backup?
mysqldump -uroot -ppassword forum > /root/backups/4.25.2011.sql

I still can’t figure out how to pass a variable to save my sql file as. How would I do that too?
My VPS is limited to 10gb and disk size is a concern or else I wouldn’t delete any files.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T16:01:25+00:00Added an answer on May 21, 2026 at 4:01 pm

    For your first part, instead of

    today = `eval date +%m.%d.%Y` #how do I add this to the backup?
    mysqldump -uroot -ppassword forum > /root/backups/4.25.2011.sql
    

    do

    today=$(date +%m.%d.%Y)
    mysqldump -uroot -ppassword forum > /root/backups/$today.sql
    

    In particular:

    • there must not be any spaces around the equals sign
    • running eval is not what you want

    The simplest way to only keep three files would be:

    rm forum-3.sql
    mv /root/backups/forum-2.sql /root/backups/forum-3.sql
    mv /root/backups/forum-1.sql /root/backups/forum-2.sql
    mysqldump -uroot -ppassword forum > /root/backups/forum-1.sql
    

    Tools like ls -l or the content of the file should tell you the date if you need it.

    If you really need the date in the file name, the easiest tool to help you is GNU date:

    dateformat="%m.%d.%Y"
    rm forum-$(date -d "-3 days" +$dateformat).sql
    mysqldump -uroot -ppassword forum > /root/backups/forum-$(date +$dateformat).sql
    

    Or use find, e.g.

    find . -name "forum*.sql" -mtime +3 -delete
    mysqldump -uroot -ppassword forum > /root/backups/forum-$(date +$dateformat).sql
    

    After that, you could look at logrotate.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a column in my SQL-2005 database that used to be a varchar(max)
I have a 'reference' SQL Server 2005 database that is used as our global
I have used code like this: http://msdn.microsoft.com/en-us/library/dw70f090.aspx to access database before when working in
Imaginary Situation: You’ve used mysqldump to create a backup of a mysql database. This
I have an sqlite database used to store information about backup jobs. Each run,
I have used visual studio(vs2010) installer to restore a database backup file to the
I have a database that I used specifically for logging actions of users. The
I have created my database, and used cake bake my_project to create my project,
In one of my applications I have a 1gb database table that is used
I have a number of scripts used to build a database. These need to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.