The National Security Agency has said it will lock down and mothball its archive of US citizens’ phone records if its legal authority to go on collecting the metadata expires as it is due to this Sunday.

The political and legal dispute will come to a head on Sunday when the Republican controlled Senate will seek a resolution before the law authorizing the controversial NSA spying program expires at 11:59pm.

The debate has pitted the Obama administration’s national security team against those who say the surveillance program, which was revealed to the American public by former NSA contractor Edward Snowden in 2013, infringes civil liberties and the US Constitution.

The hours leading up to midnight will see a jump in activity at US phone companies and at the NSA as engineers take down servers, monitoring software and hardware from the main optic cables of telephone data traffic, according to several senior officials, the LA Times reports.

"We're in uncharted waters. We have not had to confront addressing the terrorist threat without these authorities. And it's going to be fraught with unnecessary risk," said one official, as quoted by the LA Times.

Even if the Senate votes to renew legislation that allows for the mass surveillance program to continue, it would take three or four days to get it through the Foreign Intelligence Surveillance Court (FISA) before all the computer systems required could be rebooted.

READ MORE: NSA director wants ‘maritime’ law for internet

Another official said even a gap of three or four days was “playing national security roulette.”

In the unlikely scenario of the Senate voting before 8pm on Sunday in favor of renewing legislation, the NSA could stop the shutdown.

But there are many lawmakers that will fight against any renewal of the law. Senator Rand Paul (R-Ky), who is running for a presidential nomination, told supporters on Thursday that he’s determined to “relegate the NSA’s illegal spy program to the trash bin of history where it belongs.”

The NSA began the bulk collection of phone records after the September 11 attacks and FISA authorized them in 2006. But after Snowden’s leaks, Obama promised to change the NSA surveillance program.

Thus, the so-called USA Freedom Act was born, which passed the house by 338 to 88 on May 13.

It involves shifting the burden of holding data to the phone companies, who would then allow the NSA to access it. It would also mean the government would have to obtain a court order to search the records for phone numbers.

According to the director of national intelligence, James Clapper, it “preserves the essential operational capabilities of the telephone metadata program and enhances other intelligence capabilities needed to protect our nation and its partners."

It would take six months to take effect but could be derailed by Paul and other senators who argue the NSA’s surveillance remit should simply expire.

READ MORE: Obama can end NSA bulk surveillance by himself – Rand Paul

Ever prepared for a worst case scenario from politicians, the NSA has put its planning teams on “hot standby” to prepare to shut down all the networks that connect them to the nation’s phone records. They will also make sure that officials cannot access the archives.

If the legal authority expires they would “lock it down with the same certainty with which we operate,” an official said.

Along with the bulk collection of metadata, the “roving wiretap” would also expire, this allows the FBI to keep up with terrorists or criminals who use so-called “burner” phones to evade electronic surveillance.

The FBI would also lose its “lone wolf” provision which allows them to tap phones of someone they suspect might be involved in terrorist activity, but who is not connected to a known terrorist group.

"As we face a decentralized and increasingly dispersed terrorism threat, and one where [Islamic State] is extolling actors to conduct opportunistic attacks, this is not a tool that we want to see go away,” a senior official said.