The La Liga champions have not won in San Sebastian since 2007 and needed a Lionel Messi strike salvage a draw in their league visit in November.
They will get a chance to end that winless run of eight matches on January 17 before the return leg at Camp Nou a week later.
Real Madrid begin their tie with Celta Vigo at the Santiago Bernabeu as Zinedine Zidane’s side’s hunt for the treble continues.
The leaders made it a record 40 games unbeaten as they battled back to earn a 3-3 draw in the second leg of the last round against Sevilla on Thursday – eclipsing Barcelona’s previous best of 39.
Madrid’s city rivals Atletico are also into the latter stages of this year’s competition after beating Las Palmas 4-3 on aggregate.
They will meet Eibar in the last eight, while second division Alcorcon will face Alaves.
Copa del Rey draw in full:
Real Sociedad v Barcelona
Alcorcon v Alaves
Atletico Madrid v Eibar
Real Madrid v Celta Vigo